diff --git a/troll.admin.inc b/troll.admin.inc
index 945b1fe..63c59e0 100644
--- a/troll.admin.inc
+++ b/troll.admin.inc
@@ -6,18 +6,18 @@
  */
 
 /**
- * @return array
+ * Implements hook_form().
  */
 function troll_admin_settings() {
   $form['ip_settings'] = array(
     '#type' => 'fieldset',
-    '#title' => 'IP Address Banning'
+    '#title' => 'IP Address Banning',
   );
   $form['ip_settings']['troll_enable_ip_ban'] = array(
     '#type' => 'radios',
     '#title' => t('IP Address Banning'),
     '#default_value' => variable_get('troll_enable_ip_ban', 1),
-    '#options' => array('1' => t('Enable banning by IP address'), '0' => t('Disable banning by IP address'))
+    '#options' => array('1' => t('Enable banning by IP address'), '0' => t('Disable banning by IP address')),
   );
   $form['ip_settings']['troll_ip_ban_redirect'] = array(
     '#type' => 'textfield',
@@ -27,10 +27,11 @@ function troll_admin_settings() {
   );
 
   $roles = user_roles();
-  array_unshift($roles, t(' -Select Role- '));
+  array_unshift($roles, t('-Select Role-'));
+  
   $form['role_settings'] = array(
     '#type' => 'fieldset',
-    '#title' => t('User Blocking')
+    '#title' => t('User Blocking'),
   );
   $form['role_settings']['troll_block_role'] = array(
     '#type' => 'select',
@@ -63,16 +64,16 @@ function troll_ip_ban() {
     '#title' => t('Add IP Ban'),
     '#weight' => -1,
     '#collapsible' => TRUE,
-    '#collapsed' => FALSE
+    '#collapsed' => FALSE,
   );
-  $form['banfieldset']['banform'] = troll_ip_ban_form(array());
+  $form['banfieldset']['banform'] = troll_ip_ban_form(array(), $ip);
   $form['ipdisplay'] = array(
     '#type' => 'fieldset',
     '#title' => t('Banned IPs'),
     '#value' => troll_display_ip(),
     '#weight' => 0,
     '#collapsible' => TRUE,
-    '#collapsed' => FALSE
+    '#collapsed' => FALSE,
   );
   $form['#validate'] = array('troll_ip_ban_form_validate');
   return $form;
@@ -92,6 +93,7 @@ function troll_ip_ban_submit($form, &$form_state) {
  * Summary of how many IP blocks are filtered.
  *
  * @return string
+ *   the number of blacklisted IP's found
  */
 function troll_blacklist_summary() {
   $count = db_query('SELECT COUNT(net) FROM {troll_blacklist}')->fetchField();
@@ -99,45 +101,52 @@ function troll_blacklist_summary() {
 }
 
 /**
- * Gives admins a choice of how to punish blacklisted visitors
- *
- * @return array
+ * Implements hook_form().
  */
 function troll_blacklist_punishment_form() {
   $form['stutter'] = array(
     '#type' => 'checkbox',
     '#title' => t('Randomly stutter output'),
     '#default_value' => variable_get('troll_blacklist_stutter', 0),
-    '#description' => t('While outputting content, the troll module will cause Drupal to "sleep" for random intervals of 1-5 seconds to delay output.')
+    '#description' => t('While outputting content, the troll module will cause Drupal to "sleep" for random intervals of 1-5 seconds to delay output.'),
   );
   $form['mod_requests'] = array(
     '#type' => 'radios',
     '#title' => t('Page request modification'),
-    '#options' => array(t('none'), 'silent_post_drop' => 'Silently drop form post submission data', 'notice_post_drop' => 'Drop form post submission data and give a notice'),
+    '#options' => array(
+      'none' => t('none'),
+      'silent_post_drop' => 'Silently drop form post submission data',
+      'notice_post_drop' => 'Drop form post submission data and give a notice',
+    ),
     '#default_value' => variable_get('troll_blacklist_mod_requests', '0'),
-    '#description' => t('Modifies data sent by visitors from blacklisted IPs before Drupal even has a chance to process it.')
+    '#description' => t('Modifies data sent by visitors from blacklisted IPs before Drupal even has a chance to process it.'),
   );
   $form['alt_page_output'] = array(
     '#type' => 'fieldset',
-    '#title' => 'Alternate page output'
+    '#title' => 'Alternate page output',
   );
   $form['alt_page_output']['alt_page'] = array(
     '#type' => 'radios',
     '#title' => 'Alternate pages',
-    '#options' => array(t('none'), 'blank' => t('Blank pages'), '404' => t('404 every page request'), 'redirect' => t('Redirect to alternate URL')),
+    '#options' => array(
+      'none' => t('none'),
+      'blank' => t('Blank pages'),
+      '404' => t('404 every page request'),
+      'redirect' => t('Redirect to alternate URL'),
+    ),
     '#default_value' => variable_get('troll_blacklist_alt_page', '0'),
-    '#description' => t('Sends alternate page output, whether the visitor hits a real URL or not.')
+    '#description' => t('Sends alternate page output, whether the visitor hits a real URL or not.'),
   );
   $form['alt_page_output']['alt_url'] = array(
     '#type' => 'textfield',
     '#title' => t('Redirection URL'),
     '#default_value' => variable_get('troll_blacklist_alt_url', ''),
-    '#description' => t('URL to redirect blacklisted visitors to if "Redirect to alternate URL" is selected. Start with the appropriate prefix (e.g. http://)')
+    '#description' => t('URL to redirect blacklisted visitors to if "Redirect to alternate URL" is selected. Start with the appropriate prefix (e.g., http://)'),
   );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Update Blacklist Punishments'),
-    '#weight' => 1
+    '#weight' => 1,
   );
   return $form;
 }
@@ -156,15 +165,13 @@ function troll_blacklist_punishment_form_submit($form, $form_state) {
 }
 
 /**
- * Builds form array for admin to select how to import a new blacklist.
- *
- * @return array
+ * Implements hook_form().
  */
 function troll_blacklist_import_form() {
   $form['truncate_list'] = array(
     '#type' => 'checkbox',
-    '#title' => t('Truncate/delete existing blacklist before import')
-    );
+    '#title' => t('Truncate/delete existing blacklist before import'),
+  );
   $options = array();
   $options[0] = '';
   if (function_exists('gzopen')) {
@@ -179,12 +186,12 @@ function troll_blacklist_import_form() {
     '#title' => t('Download and import'),
     '#options' => $options,
     '#description' => t('Downloads supported blacklist from the internet. Please select a mirror when possible.'),
-    );
+  );
   $form['custom_list'] = array(
     '#type' => 'textfield',
     '#title' => t('List URL'),
     '#description' => t('URL of a list to import. List files should have one address per line in Classless Internet Domain Routing CIDR format (x.x.x.x/x). Individual IPs should still have /32.'),
-    );
+  );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Import List'),
@@ -210,15 +217,17 @@ function troll_blacklist_import_form_submit($form, &$form_state) {
   if (!empty($form_state['values']['custom_list'])) {
     troll_blacklist_import_url($form_state['values']['custom_list']);
   }
-  $form_state['redirect'] = 'admin/user/troll/ip_blacklist';
+  $form_state['redirect'] = 'admin/people/troll/ip_blacklist';
 }
 
 /**
- * Decyphers what dropdown selection was chosen to send for parsing out IP blocks
+ * Decyphers the dropdown selection chosen to send for parsing out IP blocks.
  *
  * @see troll_blacklist_import_form()
  * @see troll_blacklist_parse_save()
- * @param array $edit
+ *
+ * @param array $list
+ *   the blacklist import list selection
  */
 function troll_blacklist_import_list($list) {
   $files = array(
@@ -238,9 +247,10 @@ function troll_blacklist_import_list($list) {
 }
 
 /**
- * Parses a URL to send for parsing out IP blocks
+ * Parses a URL to send for parsing out IP blocks.
  *
  * @see troll_blacklist_parse_save()
+ *
  * @param array $edit
  */
 function troll_blacklist_import_url($edit) {
@@ -250,14 +260,17 @@ function troll_blacklist_import_url($edit) {
 }
 
 /**
- * Parses input file, line by line, searching for IP blocks in CIDR
- * format (x.x.x.x/x). Understands files in text, bzip, and bzip2 format,
- * where the PHP installation supports it. Writes what it finds to the
- * database as long integers.
+ * Search for IP blocks in CIDR format (x.x.x.x/x).
+ *
+ * Parses input file, line by line, searching for IP blocks. Understands files
+ * in text, bzip, and bzip2 format, where the PHP installation supports it.
+ * Writes what it finds to the database as long integers.
  *
  * @todo should probably function_exists() the compression file functions
- * @param $file_name string
- * @param $file_type string
+ *
+ * @param string $file_name
+ *
+ * @param string $file_type
  */
 function troll_blacklist_parse_save($file_name, $file_type) {
   $netmasks = array(
@@ -270,6 +283,7 @@ function troll_blacklist_parse_save($file_name, $file_type) {
     case 'gz':
       $fp = gzopen($file_name, 'r');
       break;
+
     default:
       $fp = fopen($file_name, 'r');
       break;
@@ -301,7 +315,7 @@ function troll_blacklist_parse_save($file_name, $file_type) {
         db_insert('troll_blacklist')
           ->fields(array(
             'net' => $net,
-            'bcast' => $bcast
+            'bcast' => $bcast,
           ))
           ->execute();
         $i++;
@@ -311,6 +325,7 @@ function troll_blacklist_parse_save($file_name, $file_type) {
       case 'gz':
         gzclose($fp);
         break;
+
       default:
         fclose($fp);
         break;
@@ -323,9 +338,7 @@ function troll_blacklist_parse_save($file_name, $file_type) {
 }
 
 /**
- * Form to search blacklist to see if an IP matches
- *
- * @return array
+ * Implements hook_form().
  */
 function troll_blacklist_search_form($form_state) {
   $form['ip_address'] = array(
@@ -334,11 +347,11 @@ function troll_blacklist_search_form($form_state) {
     '#size' => 15,
     '#maxlength' => 15,
     '#description' => t('Address to search for in the database of imported IP blocks.'),
-    );
+  );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Search Blacklisted IPs'),
-    '#weight' => 1
+    '#weight' => 1,
   );
   $form['result'] = array(
     '#type' => 'fieldset',
@@ -346,7 +359,7 @@ function troll_blacklist_search_form($form_state) {
     '#value' => !empty($form_state['values']['ip_address']) ? troll_blacklist_search($form_state['values']['ip_address']) : troll_blacklist_search(''),
     '#weight' => 2,
     '#collapsible' => TRUE,
-    '#collapsed' => FALSE
+    '#collapsed' => FALSE,
   );
   return $form;
 }
@@ -369,46 +382,47 @@ function troll_blacklist_search($ip_address) {
   $headers = array(
     array('data' => t('Network Address'), 'field' => 'net', 'sort' => 'asc'),
     array('data' => t('Broadcast Address'), 'field' => 'bcast'),
-    array('data' => t('Actions'), 'field' => 'delete')
+    array('data' => t('Actions'), 'field' => 'delete'),
   );
 
-  if ($ip_address == '') {
-    $result = pager_query('SELECT net, bcast FROM {troll_blacklist}', 25, 0, 'SELECT COUNT(*) FROM {troll_blacklist}');
-  }
-  else {
-    $sql = 'SELECT net, bcast FROM {troll_blacklist} WHERE net <= :longip AND bcast >= :longip';
-    $count_sql = 'SELECT COUNT(*) FROM {troll_blacklist} WHERE net <= :longip AND bcast >= :longip';
-    $longip = _troll_longip($ip_address);
-    $sql .= tablesort_sql($headers);
-    $result = pager_query($sql, 25, 0, $count_sql, array(':longip' => $longip));
+  $query = db_select('troll_blacklist', 'bl')
+    ->extend('PagerDefault')
+    ->extend('TableSort')
+    ->fields('bl', array('net', 'bcast'));
+  if (!$ip_address == '') {
+    $query
+      ->condition('net', _troll_longip($ip_address), '<=')
+      ->condition('bcast', _troll_longip($ip_address), '>=');
   }
+  $query->orderByHeader($headers);
+  $result = $query->execute();
 
-  while ($row = $result->fetchObject()) {
+  foreach ($result as $row) {
     $printnet = long2ip($row->net);
     $printbcast = long2ip($row->bcast);
-    $action = l(t('remove'), "admin/user/troll/ip_blacklist/deleteblack/{$row->net}/{$row->bcast}");
+    $action = l(t('remove'), "admin/people/troll/ip_blacklist/deleteblack/{$row->net}/{$row->bcast}");
     $rows[] = array($printnet, $printbcast, $action);
   }
-  if (!empty($rows)) {
-    $pager = theme('pager', NULL, 25, 0);
-    if (!empty($pager)) {
-      $rows[] = array(array('data' => $pager, 'colspan' => 3));
-    }
-    return theme('table', $headers, $rows);
-  }
-  else {
-    drupal_set_message(t('No matches found.'));
-    return FALSE;
-  }
+
+  $build['blacklist_table'] = array(
+    '#theme' => 'table',
+    '#header' => $headers,
+    '#rows' => $rows,
+    '#empty' => t('No IP addresses are whitelisted'),
+  );
+  $form['blacklist_pager'] = array('#theme' => 'pager');
+  return drupal_render($build);
 }
 
 /**
- * Form builder function
+ * Form builder function.
+ *
+ * @param string $net
+ *   Not used, here for later Implements whitelist editing
+ * @param string $bcast
+ *   Not used, here for later Implements whitelist editing
  *
- * @param $net string Not used, here for later implementation of whitelist editing
- * @param $bcast string Not used, here for later implementation of whitelist editing
  * @see troll_whitelist_form()
- * @return string
  */
 function troll_whitelist($net = NULL, $bcast = NULL) {
   $sql = 'SELECT net, bcast FROM {troll_whitelist}';
@@ -417,33 +431,39 @@ function troll_whitelist($net = NULL, $bcast = NULL) {
   $headers = array(
     array('data' => t('Start/Network Address'), 'field' => 'net', 'sort' => 'asc'),
     array('data' => t('End/Broadcast Address'), 'field' => 'bcast'),
-    array('data' => t('Actions'), 'field' => 'delete')
+    array('data' => t('Actions'), 'field' => 'delete'),
   );
 
-  $sql .= tablesort_sql($headers);
-  $result = pager_query($sql, 25, 0, $count_sql);
-  while ($row = db_fetch_object($result)) {
+  $query = db_select('troll_whitelist', 't')
+    ->extend('PagerDefault')
+    ->extend('TableSort');
+  $result = $query
+    ->fields('t', array('net', 'bcast'))
+    ->limit(25)
+    ->orderByHeader($headers)
+    ->execute();
+  foreach ($result as $row) {
     $printnet = long2ip($row->net);
     $printbcast = long2ip($row->bcast);
-    $action = l(t('remove'), "admin/user/troll/ip_blacklist/deletewhite/{$row->net}/{$row->bcast}");
+    $action = l(t('remove'), "admin/people/troll/ip_blacklist/deletewhite/{$row->net}/{$row->bcast}");
     $rows[] = array($printnet, $printbcast, $action);
   }
 
-  $pager = theme('pager', NULL, 25, 0);
-  if (!empty($pager)) {
-    $rows[] = array(array('data' => $pager, 'colspan' => 3));
-  }
+  $build['whitelist_table'] = array(
+    '#theme' => 'table',
+    '#header' => $headers,
+    '#rows' => $rows,
+    '#empty' => t('No IP addresses are whitelisted'),
+  );
+  $form['whitelist_pager'] = array('#theme' => 'pager');
 
-  return theme('table', $headers, $rows);
+  return drupal_render($build);
 }
 
 /**
- * Display form for creating new whitelist block and table of current whitelisted IPs.
- *
- * @todo make this also useful for editing existing whitelist entries
- * @return array
+ * Implements hook_form().
  */
-function troll_whitelist_form($form_state) {
+function troll_whitelist_form($form, $form_state) {
   $form['whitelist_addr1'] = array(
     '#type' => 'textfield',
     '#title' => t('Starting IP Address'),
@@ -451,7 +471,7 @@ function troll_whitelist_form($form_state) {
     '#maxlength' => 15,
     '#default_value' => isset($net) ? long2ip($net) : '',
     '#description' => t('IP or start to range of IPs to whitelist.'),
-    '#required' => TRUE
+    '#required' => TRUE,
   );
   $form['whitelist_addr2'] = array(
     '#type' => 'textfield',
@@ -460,12 +480,12 @@ function troll_whitelist_form($form_state) {
     '#maxlength' => 15,
     '#default_value' => isset($bcast) ? long2ip($bcast) : '',
     '#description' => t('End of IP range to whitelist. If whitelisting a single IP, leave this blank.'),
-    '#required' => false
+    '#required' => FALSE,
   );
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Insert Whitelist IPs'),
-    '#weight' => 1
+    '#weight' => 1,
   );
   $form['whitelist'] = array(
     '#type' => 'fieldset',
@@ -473,13 +493,13 @@ function troll_whitelist_form($form_state) {
     '#value' => troll_whitelist(),
     '#weight' => 2,
     '#collapsible' => TRUE,
-    '#collapsed' => FALSE
+    '#collapsed' => FALSE,
   );
   return $form;
 }
 
 /**
- * Insert a new IP block into the whitelist
+ * Insert a new IP block into the whitelist.
  *
  * @param array $edit
  */
@@ -495,13 +515,16 @@ function troll_whitelist_form_submit($form, &$form_state) {
     unset($temp);
   }
   db_delete('troll_whitelist')
-    ->condition(db_and()->condition('net', $longip1)->condition('bcast', $longip2))
+    ->condition(db_and()
+    ->condition('net', $longip1)
+    ->condition('bcast', $longip2))
     ->execute();
   db_insert('troll_whitelist')
     ->fields(array(
       'net' => $longip1,
-      'bcast' => $longip2
-    ))
+      'bcast' => $longip2,
+    )
+  )
     ->execute();
   drupal_set_message(t('IP range %ip1 to %ip2 whitelisted.', array('%ip1' => long2ip($longip1), '%ip2' => long2ip($longip2))));
 }
@@ -509,55 +532,64 @@ function troll_whitelist_form_submit($form, &$form_state) {
 /**
  * Menu callback: block a user and redirect to search page.
  *
- * @param $uid
+ * @param int $uid
+ *   the users ID to block
  */
-function troll_confirm_block_user_form($form_state, $uid) {
+function troll_confirm_block_user_form($form, &$form_state, $uid) {
   $account = user_load($uid);
   if (!$account) {
-    drupal_goto('admin/user/troll');
+    drupal_goto('admin/people/troll');
   }
   $form['uid'] = array(
     '#type' => 'value',
     '#value' => $uid,
   );
-  return confirm_form($form, t('Block user %username?', array('%username' => $account->name)), 'admin/user/troll', t('Are you sure you want to block this user?'));
+  return confirm_form($form, t('Block user %username?', array('%username' => $account->name)), 'admin/people/troll', t('Are you sure you want to block this user?'));
 }
-
+/**
+ * Submit handler for block user form. 
+ */
 function troll_confirm_block_user_form_submit($form, &$form_state) {
   troll_block_user($form_state['values']['uid']);
-  $form_state['redirect'] = 'admin/user/troll';
+  $form_state['redirect'] = 'admin/people/troll';
 }
 
 /**
- * IP banning form.
- *
- * @param $iid int
- * @return array
+ * Implements hook_form().
  */
-function troll_ip_ban_form($form_state, $iid = NULL) {
+function troll_ip_ban_form($form, &$form_state) {
+  if (isset($form_state['build_info']['args'][0]) && $form_state['build_info']['args'][0]) {
+    $ip = $form_state['build_info']['args'][0];
+  }
+  else {
+    $ip = '';
+  }
+
+  $ip = db_query_range('SELECT * FROM {troll_ip_ban} WHERE ip_address = :ip', 0, 1, array(
+      ':ip' => $ip))->fetchObject();
+
   $form['submit'] = array(
     '#type' => 'submit',
-    '#value' => (isset($iid)) ? t('Update Banned IP') : t('Ban IP'),
+    '#value' => (isset($ip->ip_address)) ? t('Update Banned IP') : t('Ban IP'),
     '#weight' => 1,
   );
-
-  $ip = db_query_range('SELECT * FROM {troll_ip_ban} WHERE iid = :iid', array(':iid' => $iid), 0, 1)->fetchObject();
-  $form['iid'] = array(
-    '#type' => 'value',
-    '#value' => !empty($ip->iid) ? $ip->iid : '',
-  );
   $form['ip_address'] = array(
     '#type' => 'textfield',
     '#title' => t('IP Address'),
     '#default_value' => !empty($ip->ip_address) ? $ip->ip_address : '',
     '#description' => t('The IP address to ban.'),
-    '#required' => TRUE
+    '#required' => TRUE,
   );
+
   $form['domain_name'] = array(
     '#type' => 'textfield',
     '#title' => t('Domain Name'),
     '#default_value' => !empty($ip->domain_name) ? $ip->domain_name : (!empty($ip->ip_address) ? gethostbyaddr($ip->ip_address) : ''),
-    '#description' => t('The Domain Name of the IP address to ban - for reference only.')
+    '#description' => t('The Domain Name of the IP address to ban - for reference only.'),
+  );
+  $form['iid'] = array(
+    '#type' => 'value',
+    '#value' => !empty($ip->iid) ? $ip->iid : '',
   );
 
   troll_ip_ban_expire_form($form, $ip);
@@ -566,7 +598,7 @@ function troll_ip_ban_form($form_state, $iid = NULL) {
 }
 
 /**
- * troll_ip_ban form validate callback function.
+ * IP ban form validate callback function.
  *
  * @see troll_ip_ban_form()
  */
@@ -583,7 +615,7 @@ function troll_ip_ban_form_validate($form, &$form_state) {
  */
 function troll_ip_ban_form_submit($form, &$form_state) {
   troll_update_ip($form_state['values']);
-  $form_state['redirect'] = 'admin/user/troll/ip_ban';
+  $form_state['redirect'] = 'admin/people/troll/ip_ban';
 }
 
 /**
@@ -592,14 +624,17 @@ function troll_ip_ban_form_submit($form, &$form_state) {
 function troll_ip_ban_expire_form(&$form, $ip) {
   $timestamp = isset($ip->expires) ? $ip->expires : REQUEST_TIME;
 
-  $date = getdate(gmmktime());
+  $date = getdate(REQUEST_TIME);
   $curyear = $date['year'];
   $i = 0;
   while ($i < 10) {
     $years[$curyear + $i] = $curyear + $i;
     $i++;
   }
-  $months = array(1 => t('January'), t('February'), t('March'), t('April'), t('May'), t('June'), t('July'), t('August'), t('September'), t('October'), t('November'), t('December'));
+  $months = array(1 => t('January'), t('February'), t('March'), t('April'),
+    t('May'), t('June'), t('July'), t('August'), t('September'), t('October'),
+    t('November'), t('December'),
+  );
   for ($i = 1; $i <= 31; $i++) {
     $days[$i] = $i;
   }
@@ -609,26 +644,26 @@ function troll_ip_ban_expire_form(&$form, $ip) {
     '#title' => t('Expires'),
     '#prefix' => '<div class="container-inline"><div class="day">',
     '#suffix' => '</div></div>',
-    '#description' => t('The ban will be removed after this day.')
+    '#description' => t('The ban will be removed after this day.'),
   );
   $form['timestamp']['expires'] = array(
     '#type' => 'checkbox',
-    '#default_value' => isset($ip->expires) ? TRUE : FALSE
+    '#default_value' => isset($ip->expires) ? TRUE : FALSE,
   );
   $form['timestamp']['month'] = array(
     '#type' => 'select',
     '#default_value' => date('n', $timestamp),
-    '#options' => $months
+    '#options' => $months,
   );
   $form['timestamp']['day'] = array(
     '#type' => 'select',
     '#default_value' => date('j', $timestamp),
-    '#options' => $days
+    '#options' => $days,
   );
   $form['timestamp']['year'] = array(
     '#type' => 'select',
     '#default_value' => date('Y', $timestamp),
-    '#options' => $years
+    '#options' => $years,
   );
 }
 
@@ -636,8 +671,9 @@ function troll_ip_ban_expire_form(&$form, $ip) {
  * IP ban information form.
  */
 function troll_display_ip() {
-
+  $build = array();
   $rows = array();
+
   $sql = 'SELECT iid, ip_address, domain_name, expires, uid FROM {troll_ip_ban}';
   $count_sql = 'SELECT COUNT(*) FROM {troll_ip_ban}';
 
@@ -645,37 +681,52 @@ function troll_display_ip() {
     array('data' => t('IP Address'), 'field' => 'ip_address'),
     array('data' => t('Domain Name'), 'field' => 'domain_name'),
     array('data' => t('Expires'), 'field' => 'expires', 'sort' => 'desc'),
-    array('data' => t('Actions'), 'field' => 'delete')
-  );
-
-  $sql .= tablesort_sql($headers);
-  $result = pager_query($sql, 25, 0, $count_sql);
-  while ($row = $result->fetchObject()) {
-    $thisip = l($row->ip_address, 'admin/user/troll/ip_ban/edit/' . $row->iid);
-    $thisdom = l(($row->domain_name ? $row->domain_name : gethostbyname($row->ip_address)), 'admin/user/troll/ip_ban/edit/' . $row->iid);
+    array('data' => t('Actions'), 'field' => 'delete'),
+  );
+
+  $query = db_select('troll_ip_ban')
+    ->extend('PagerDefault')
+    ->extend('TableSort');
+  $query->fields('troll_ip_ban', array(
+    'iid',
+    'ip_address',
+    'domain_name',
+    'expires',
+    'uid',
+  ));
+  $query->orderByHeader($headers);
+  $result = $query->execute();
+  foreach ($result as $row) {
+    $thisip = l($row->ip_address, 'admin/people/troll/ip_ban/edit/' . $row->ip_address);
+    $thisdom = l(($row->domain_name ? $row->domain_name : gethostbyname($row->ip_address)), 'admin/people/troll/ip_ban/edit/' . $row->ip_address);
     $expires = ($row->expires ? date('M d, Y', $row->expires) : t('never'));
-    $action = l(t('remove'), 'admin/user/troll/ip_ban/delete/' . $row->iid);
+    $action = l(t('remove'), 'admin/people/troll/ip_ban/delete/' . $row->ip_address);
     $rows[] = array($thisip, $thisdom, $expires, $action);
   }
 
-  $pager = theme('pager', NULL, 25, 0);
-  if (!empty($pager)) {
-    $rows[] = array(array('data' => $pager, 'colspan' => 5));
-  }
+  $build['ipdisplay_table'] = array(
+    '#theme' => 'table',
+    '#header' => $headers,
+    '#rows' => $rows,
+    '#empty' => t('No IP addresses are Banned'),
+  );
+  $build['ipdisplay_pager'] = array('#theme' => 'pager');
 
-  return theme('table', $headers, $rows);
+  return drupal_render($build);
 }
 
 /**
  * IP ban delete confirmation form.
  */
-function troll_confirm_delete_ip_form($form_state, $iid) {
-  $ip = db_query_range('SELECT ip_address FROM {troll_ip_ban} WHERE iid = :iid', array(':iid' => $iid), 0, 1)->fetchField();
-  $form['iid'] = array(
+function troll_confirm_delete_ip_form($form, &$form_state, $ip) {
+
+  $ip = db_query('SELECT ip_address FROM {troll_ip_ban} WHERE ip_address = :ip',
+    array(':ip' => $form_state['build_info']['args'][0]))->fetchField();
+  $form['ip_address'] = array(
     '#type' => 'value',
-    '#value' => $iid,
+    '#value' => trim($ip),
   );
-  return confirm_form($form, t('Remove Ban for IP %ip?', array('%ip' => $ip)), 'admin/user/troll/ip_ban', t('Are you sure you want to remove the ban on this IP?'));
+  return confirm_form($form, t('Remove Ban for IP %ip?', array('%ip' => $ip)), 'admin/people/troll/ip_ban', t('Are you sure you want to remove the ban on this IP?'));
 }
 
 /**
@@ -684,15 +735,15 @@ function troll_confirm_delete_ip_form($form_state, $iid) {
  * @see troll_confirm_delete_ip_form()
  */
 function troll_confirm_delete_ip_form_submit($form, &$form_state) {
-  troll_remove_ip($form_state['values']['iid']);
-  $form_state['redirect'] = 'admin/user/troll/ip_ban';
+  troll_remove_ip($form_state['values']['ip_address']);
+  $form_state['redirect'] = 'admin/people/troll/ip_ban';
 }
 
 /**
  * IP ban confirmation form.
  */
-function troll_confirm_ban_ip_form($form_state, $uid) {
-  $ip = db_query_range('SELECT ip_address FROM {troll_ip_track} WHERE uid = :uid ORDER BY accessed DESC', array(':uid' => $uid), 0, 1)->fetchField();
+function troll_confirm_ban_ip_form($form, &$form_state) {
+  $ip = db_query_range('SELECT ip_address FROM {troll_ip_track} WHERE uid = :uid ORDER BY accessed DESC', 0, 1, array(':uid' => $uid))->fetchField();
   $form['ip_address'] = array(
     '#type' => 'value',
     '#value' => $ip->ip_address,
@@ -701,9 +752,7 @@ function troll_confirm_ban_ip_form($form_state, $uid) {
     '#type' => 'value',
     '#value' => gethostbyaddr($ip->ip_address),
   );
-  troll_ip_ban_expire_form($form, $ip);
-
-  return confirm_form($form, t('Ban IP %ip?', array('%ip' => $ip)), 'admin/user/troll/ip_ban', t('Are you sure you want to ban this IP?'));
+  return confirm_form($form, t('Ban IP %ip?', array('%ip' => $ip)), 'admin/people/troll/ip_ban', t('Are you sure you want to ban this IP?'));
 }
 
 /**
@@ -713,33 +762,39 @@ function troll_confirm_ban_ip_form($form_state, $uid) {
  */
 function troll_confirm_ban_ip_form_submit($form, &$form_state) {
   troll_insert_ip($form_state['values']);
-  $form_state['redirect'] = 'admin/user/troll';
+  $form_state['redirect'] = 'admin/people/troll';
 }
 
 /**
- * Confirmation form for deleting a blacklist IP block
+ * Confirmation form for deleting a blacklist IP block.
  *
- * @param integer $net IP in long format
- * @param integer $bcast IP in long format
+ * @param int $net
+ *   IP network address in long format
+ * @param int $bcast
+ *   IP broadcast address in long format
  */
-function troll_confirm_delete_black_block_form($form_state, $net, $bcast) {
+function troll_confirm_delete_black_block_form($form, &$form_state, $net, $bcast) {
+
   $result = db_query('SELECT COUNT(net) FROM {troll_blacklist} WHERE net = :net AND bcast = :bcast', array(':net' => $net, ':bcast' => $bcast))->fetchField();
   if (empty($result)) {
     drupal_set_message(t('No such IP range found in the database.'));
-    drupal_goto('admin/user/troll/ip_blacklist/search');
+    drupal_goto('admin/people/troll/ip_blacklist/search');
   }
   $form['net'] = array(
     '#type' => 'value',
-    '#value' => $net
+    '#value' => $net,
   );
   $form['bcast'] = array(
     '#type' => 'value',
-    '#value' => $bcast
+    '#value' => $bcast,
   );
   return confirm_form(
     $form,
-    t('Remove listing for IP block %ip1 to %ip2?', array('%ip1' => long2ip($net), '%ip2' => long2ip($bcast))),
-    'admin/user/troll/ip_blacklist/search',
+    t('Remove listing for IP block %ip1 to %ip2?', array(
+      '%ip1' => long2ip($net),
+      '%ip2' => long2ip($bcast),
+    )),
+    'admin/people/troll/ip_blacklist/search',
     t('Are you sure you want to remove this IP block from the blacklist?'),
     t('Confirm Blacklist Removal')
   );
@@ -752,34 +807,50 @@ function troll_confirm_delete_black_block_form($form_state, $net, $bcast) {
  */
 function troll_confirm_delete_black_block_form_submit($form, &$form_state) {
   troll_remove_blacklist($form_state['values']['net'], $form_state['values']['bcast']);
-  $form_state['redirect'] = 'admin/user/troll/ip_blacklist/search';
+  $form_state['redirect'] = 'admin/people/troll/ip_blacklist/search';
 }
 
 /**
- * Confirmation form for deleting a whitelist IP block
+ * Confirmation form for deleting a whitelist IP block.
  *
- * @param integer $net IP in long format
- * @param integer $bcast IP in long format
+ * @param int $net
+ *   IP network address in long format
+ * @param int $bcast
+ *   IP broadcast address in long format
  */
-function troll_confirm_delete_white_block_form($form_state, $net, $bcast) {
-  $result = db_query('SELECT COUNT(net) FROM {troll_whitelist} WHERE net = :net AND bcast = :bcast', array(':net' => $net, ':bcast' => $bcast))->fetchField();
+function troll_confirm_delete_white_block_form($form, &$form_state, $net, $bcast) {
+
+  $result = db_query('SELECT tw.* FROM {troll_whitelist} tw WHERE net = :net AND bcast = :bcast', array(
+      ':net' => $net,
+      ':bcast' => $bcast,
+    )
+  );
   if (empty($result)) {
     drupal_set_message(t('No such IP range found in the database.'));
-    drupal_goto('admin/user/troll/ip_blacklist/whitelist');
+    drupal_goto('admin/people/troll/ip_blacklist/whitelist');
   }
+
+  foreach ($result as $row) {
+    $net = $row->net;
+    $bcast = $row->bcast;
+  }
+
   $form['net'] = array(
     '#type' => 'value',
-    '#value' => $net
+    '#value' => $net,
   );
   $form['bcast'] = array(
     '#type' => 'value',
-    '#value' => $bcast
+    '#value' => $bcast,
   );
 
   return confirm_form(
     $form,
-    t('Remove listing for IP block %ip1 to %ip2?', array('%ip1' => long2ip($net), '%ip2' => long2ip($bcast))),
-    'admin/user/troll/ip_blacklist/whitelist',
+    t('Remove listing for IP block %ip1 to %ip2?', array(
+      '%ip1' => long2ip($net),
+      '%ip2' => long2ip($bcast),
+    )),
+    'admin/people/troll/ip_blacklist/whitelist',
     t('Are you sure you want to remove this IP block from the whitelist?'),
     t('Confirm Whitelist Removal')
   );
@@ -792,19 +863,17 @@ function troll_confirm_delete_white_block_form($form_state, $net, $bcast) {
  */
 function troll_confirm_delete_white_block_form_submit($form, &$form_state) {
   troll_remove_whitelist($form_state['values']['net'], $form_state['values']['bcast']);
-  $form_state['redirect'] = 'admin/user/troll/ip_blacklist/whitelist';
+  $form_state['redirect'] = 'admin/people/troll/ip_blacklist/whitelist';
 }
 
 /**
- * User search form.
- *
- * @return array
+ * Implements hook_form().
  */
-function troll_search_form($form_state) {
+function troll_search_form($form, &$form_state) {
   $form['search'] = array(
     '#type' => 'fieldset',
     '#title' => t('Search Users'),
-    '#collapsible' => TRUE
+    '#collapsible' => TRUE,
   );
   $form['search']['username'] = array(
     '#type' => 'textfield',
@@ -812,260 +881,345 @@ function troll_search_form($form_state) {
   );
   $form['search']['mail'] = array(
     '#type' => 'textfield',
-    '#title' => t('Email')
+    '#title' => t('Email'),
   );
   $form['search']['ip_address'] = array(
     '#type' => 'textfield',
-    '#title' => t('IP Address')
+    '#title' => t('IP Address'),
   );
   $form['search']['date_created'] = array(
     '#type' => 'textfield',
     '#title' => t('Account Date Created'),
-    '#description' => t('Enter date in mm/dd/yyyy format. Returns all users created after the date entered.')
+    '#description' => t('Enter date in mm/dd/yyyy format. Returns all users created after the date entered.'),
   );
   $form['search']['submit'] = array(
     '#type' => 'submit',
-    '#value' => t('Search Users')
+    '#value' => t('Search Users'),
   );
   $form['users'] = array(
     '#type' => 'fieldset',
     '#title' => t('Users'),
-    '#value' => isset($form_state['values']) ? troll_list_users($form_state['values']) : troll_list_users(array()),
+    '#value' => isset($form_state['values']) ? troll_list_users($form_state['values']) : troll_list_users($edit = NULL),
     '#weight' => 2,
     '#collapsible' => TRUE,
-    '#collapsed' => FALSE
+    '#collapsed' => FALSE,
   );
+
   return $form;
 }
 
+/*
+ * Submit handler for for troll_search_form.
+ */
 function troll_search_form_submit($form, &$form_state) {
+  //echo "<pre> ; 886";print_r($form_state);echo "</pre>";
   $form_state['rebuild'] = TRUE;
 }
 
 /**
  * User list form.
  *
- * @param $edit array
+ * @param array $edit
  */
 function troll_list_users($edit) {
 
-  $args = array();
-  $where[] = 'u.uid <> 0';
+  $headers = array(
+    array('data' => t('Username'), 'field' => 'u.name'),
+    array('data' => t('Email'), 'field' => 'u.mail'),
+    array('data' => t('Status'), 'field' => 'u.status'),
+    array('data' => t('IP Address'), 'field' => 't.ip_address'),
+    array('data' => t('Last Access'), 'field' => 't.created'),
+    array('data' => t('Account Created'), 'field' => 'u.created'),
+    array('data' => t('Actions'), 'field' => 'actions'),
+  );
+
+  $query = db_select('users', 'u')
+      ->extend('PagerDefault')
+      ->extend('TableSort');
+  $query->leftJoin('troll_ip_track', 't', 'u.uid = t.uid');
+  $query->condition('u.uid', 0, '<>');
 
   if (!empty($edit['username'])) {
-    $where[] = "LOWER(u.name) LIKE '%:name%' ";
-    $args[':name'] = drupal_strtolower($edit['username']);
+    $query->condition('u.name', drupal_strtolower($edit['username']), 'LIKE');
   }
   if (!empty($edit['mail'])) {
-    $where[] = "LOWER(u.mail) LIKE '%:mail%' ";
-    $args[':mail'] = drupal_strtolower($edit['mail']);
+    $query->condition('u.mail', drupal_strtolower($edit['mail']), 'LIKE');
   }
   if (!empty($edit['ip_address'])) {
-    $where[] = "LOWER(t.ip_address) LIKE '%:ip_address%' ";
-    $args[':ip_address'] = drupal_strtolower($edit['ip_address']);
+    $query->condition('t.ip_address', drupal_strtolower($edit['ip_address']), 'LIKE');
   }
   if (!empty($edit['date_created'])) {
-    $where[] = "u.created > :created ";
-    $args[':created'] = drupal_strtotime($edit['date_created']);
+    $query->condition('u.created', drupal_strtolower($edit['date_created']), 'LIKE');
   }
 
-  $sql = "SELECT u.uid, u.name, u.mail, u.status, t.ip_address, MAX(t.accessed) AS recorded, u.created FROM {users} u LEFT JOIN {troll_ip_track} t ON u.uid = t.uid";
+  $query
+    ->groupBy('u.uid')
+    ->groupBy('u.name')
+    ->groupBy('u.mail')
+    ->groupBy('u.status')
+    ->groupBy('t.ip_address')
+    ->groupBy('u.created');
+  $query
+    ->fields('u', array('uid', 'name', 'mail', 'status', 'created'))
+    ->fields('t', array('ip_address', 'accessed'))
 
-  $sql .= ' WHERE ' . implode(' AND ', $where);
-
-  $headers = array(
-    array('data' => t('Username'), 'field' => 'u.name'),
-    array('data' => t('Email'), 'field' => 'u.mail'),
-    array('data' => t('Status'), 'field' => 'u.status'),
-    array('data' => t('IP Address'), 'field' => 't.ip_address'),
-    array('data' => t('Last Access'), 'field' => 't.created'),
-    array('data' => t('Account Created'), 'field' => 'u.created'),
-    array('data' => t('Actions'), 'field' => 'actions')
-  );
+    ->orderByHeader($headers);
 
-  $sql .= ' GROUP BY u.uid, u.name, u.mail, u.status, t.ip_address, u.created';
-  $sql .= tablesort_sql($headers);
+  $results = $query->execute();
 
-  $count_sql = 'SELECT COUNT(*) FROM {users} u LEFT JOIN {troll_ip_track} t ON u.uid = t.uid WHERE ' . implode(' AND ', $where) . ' AND u.uid <> 0';
-  $result = pager_query($sql, 25, 0, $count_sql, $args);
+  $user_count = $query->countQuery()->execute()->fetchField();
 
-  while ($user = db_fetch_object($result)) {
-    $name = l($user->name, 'admin/user/troll/search/view/' . $user->uid, array('title' => t('View detailed user information')));
+  foreach ($results as $user) {
+    $name = l($user->name, 'admin/people/troll/search/view/' . $user->uid, array('title' => t('View detailed user information')));
     $email = $user->mail;
     $status = ($user->status ? t('Active') : t('Blocked'));
-    $ip = ($user->ip_address ? l($user->ip_address, 'admin/user/troll/search/view/' . $user->uid, array('title' => t('View detailed user information'))) : t('none'));
-    $recorded = ($user->recorded ? date('M d, Y', $user->recorded) : t('none recorded'));
+    $ip = ($user->ip_address ? l($user->ip_address, 'admin/people/troll/search/view/' . $user->uid, array('title' => t('View detailed user information'))) : t('none'));
+    $recorded = ($user->accessed ? date('M d, Y', $user->accessed) : t('none recorded'));
     $created = date('M d, Y', $user->created);
     $actions = array();
-
     if (!$user->status) {
-      $actions[] = array('title' => t('Edit User'), 'href' => "user/{$user->uid}/edit");
+      $actions[] = l(t('Edit User'), "user/{$user->uid}/edit");
     }
-    else if (variable_get('troll_block_role', NULL)) {
-      $actions[] = array('title' => t('Block User'), 'href' => 'admin/user/troll/search/block/' . $user->uid);
+    elseif (variable_get('troll_block_role', NULL)) {
+      $actions[] = l(t('Block User'), 'admin/people/troll/search/block/' . $user->uid);
     }
     else {
-      $actions[] = array('title' => t('Set up Block Role'), 'href' => 'admin/user/troll/settings');
+      $actions[] = l(t('Set up Block Role'), 'admin/people/troll/settings');
     }
     if ($user->ip_address) {
-      $actions[] = array('title' => t('Ban IP'), 'href' => 'admin/user/troll/ip_ban/user/' . $user->uid);
+      $actions[] = l(t('Ban IP'), 'admin/people/troll/ip_ban/user/' . $user->uid);
     }
-    $action = theme('links', $actions);
-    $rows[] = array($name, $email, $status, $ip, $recorded, $created, $action);
+    $rows[] = array(
+      $name,
+      $email,
+      $status,
+      $ip,
+      $recorded,
+      $created,
+      implode(', ', $actions),
+    );
   }
 
-  $pager = theme('pager', NULL, 25);
+  $build['list_users_table'] = array(
+    '#theme' => 'table',
+    '#header' => $headers,
+    '#rows' => $rows,
+    '#empty' => t('No IP addresses are whitelisted'),
+  );
 
-  if (!empty($pager)) {
-    $rows[] = array(array('data' => $pager, 'colspan' => 7));
+  if ($user_count > 1) {
+    $build['list_users_pager'] = array('#theme' => 'pager');
   }
 
-  return theme('table', $headers, $rows);
+  return drupal_render($build);
 }
 
 /**
  * User detail form.
  *
- * This is not an actual form; the form API is just being used for easy formatting.
+ * This is not an actual form; the form API is being used for easy formatting.
  *
- * @param $uid int
- * @return string
+ * @param int $uid
+ *   user ID
+ * 
+ * @return array
+ *   returns a rendered array
  */
 function troll_search_user_detail($uid) {
+
   $u = user_load($uid);
-  $u->ip = db_query_range('SELECT t.ip_address FROM {troll_ip_track} t WHERE t.uid = :uid GROUP BY t.uid, t.ip_address', array(':uid' => $uid), 0, 1)->fetchField();
+  $u->ip = db_query('SELECT t.ip_address FROM {troll_ip_track} t WHERE t.uid = :uid GROUP BY t.uid, t.ip_address', array(':uid' => $u->uid))->fetchField();
+  $build = array();
 
   $form['details'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Account Details for %username', array('%username' => $u->name))
+    '#title' => t('Account Details for %username', array('%username' => $u->name)),
   );
 
   $form['details'][] = array(
     '#type' => 'item',
     '#title' => t('User Name'),
-    '#value' => theme('username', $u),
+    '#markup' => t('%username', array('%username' => $u->name)),
   );
+
   $form['details'][] = array(
     '#type' => 'item',
     '#title' => t('Email'),
-    '#value' => $u->mail
+    '#markup' => $u->mail,
   );
+
   $form['details'][] = array(
     '#type' => 'item',
     '#title' => t('User ID'),
-    '#value' => $uid
+    '#markup' => $u->uid,
   );
+
   $form['details'][] = array(
     '#type' => 'item',
     '#title' => t('Account Created'),
-    '#value' => format_date($u->created, 'large')
+    '#markup' => format_date($u->created, 'large'),
   );
+
+  if (isset($u->access) and ($u->access >= $u->created)) {
+    $last_access = format_date($u->access, 'large');
+  }
+  else {
+    $last_access = "Has never logged in";
+  }
   $form['details'][] = array(
     '#type' => 'item',
     '#title' => t('Last Access'),
-    '#value' => format_date($u->access, 'large')
+    '#markup' => $last_access,
   );
   $form['details'][] = array(
     '#type' => 'item',
     '#title' => t('Status'),
-    '#value' => ($u->status ? t('Active') : t('Blocked'))
+    '#markup' => ($u->status ? t('Active') : t('Blocked')),
   );
   $form['details'][] = array(
     '#type' => 'item',
     '#title' => t('User Roles'),
-    '#value' => implode(', ', $u->roles)
+    '#markup' => implode(', ', $u->roles),
   );
   if ($u->status) {
-    $links[] = array('title' => t('Block User'), 'href' => "admin/user/troll/search/block/$uid");
+    $links[] = array('title' => t('Block User'), 'href' => "admin/people/troll/search/block/$u->uid");
   }
   else {
-    $links[] = array('title' => t('Edit User'), 'href' => "user/$uid/edit");
+    $links[] = array('title' => t('Edit User'), 'href' => "user/$u->uid/edit");
   }
   if ($u->ip) {
-    $links[] = array('title' => t('Ban IP'), 'href' => "admin/user/troll/ip_ban/user/$uid");
+    $links[] = array('title' => t('Ban IP'), 'href' => "admin/people/troll/ip_ban/people/$u->uid");
   }
   $form['details'][] = array(
     '#type' => 'item',
     '#title' => t('Actions'),
-    '#value' => theme('links', $links)
+    '#markup' => theme('links', array(
+      'links' => $links,
+      'attributes' => array('class' => array('links', 'inline')))
+    ),
   );
 
-  $content = drupal_render($form);
+  $build['details'] = ($form['details']);
 
   // Get IP history.
-  $result = db_query('SELECT * FROM {troll_ip_track} WHERE uid = :uid ORDER BY created DESC', array(':uid' => $uid));
-  while ($ip = $result->fetchObject()) {
-    $banned = db_query_range('SELECT iid, ip_address, expires FROM {troll_ip_ban} WHERE ip_address = :ip_address', array(':ip_address' => $ip->ip_address), 0, 1)->fetchObject();
+  $result = db_query('SELECT * FROM {troll_ip_track} WHERE uid = :uid ORDER BY created DESC', array(':uid' => $u->uid));
+  $rows = array();
+  foreach ($result as $ip) {
+    $banned = db_query_range('SELECT iid, ip_address, expires FROM {troll_ip_ban} WHERE ip_address = :ip_address', 0, 1, array(':ip_address' => $ip->ip_address))->fetchObject();
     if (!empty($banned->ip_address)) {
       if (!empty($banned->expires) && $banned->expires < REQUEST_TIME) {
-        $status = l(t('expired'), 'admin/user/troll/ip_ban/edit/' . $banned->iid, array('title' => t('Edit IP ban information')));
+        $status = l(t('expired'), 'admin/people/troll/ip_ban/edit/' . $banned->iid, array('title' => t('Edit IP ban information')));
       }
       else {
-        $status = l(t('banned'), 'admin/user/troll/ip_ban/edit/' . $banned->iid, array('title' => t('Edit IP ban information')));
+        $status = l(t('banned'), 'admin/people/troll/ip_ban/edit/' . $banned->iid, array('title' => t('Edit IP ban information')));
       }
     }
     else {
-      $status = l(t('not banned'), 'admin/user/troll/ip_ban/user/' . $uid, array('title' => t('Ban this IP')));
+      $status = l(t('not banned'), 'admin/people/troll/ip_ban/people/' . $uid->uid, array('title' => t('Ban this IP')));
     }
-    $rows[] = array($ip->ip_address, $status, format_date($ip->accessed, 'large'), format_date($ip->created, 'large'), exec('host ' . $ip->ip_address));
+    $rows[] = array(
+      $ip->ip_address,
+      $status,
+      format_date($ip->accessed, 'large'),
+      format_date($ip->created, 'large'),
+      exec('host ' . $ip->ip_address),
+    );
   }
 
-  if ($rows) {
-    $pheader = array(t('IP'), t('Status'), t('Last Access'), t('First Access'), t('Host Information'));
-    $posts = theme('table', $pheader, $rows);
-  }
-  $content .= theme('box', t('IP History'), ($posts ? $posts : t('No ip history')));
+  $pheader = array(
+    t('IP'),
+    t('Status'),
+    t('Last Access'),
+    t('First Access'),
+    t('Host Information'),
+  );
+
+  $build['pager_table'] = array(
+    '#theme' => 'table',
+    '#header' => $pheader,
+    '#rows' => $rows,
+    '#empty' => t("No IP addresses tracked"),
+  );
 
+  // Attach the pager theme.
+  $build['pager_pager'] = array('#theme' => 'pager');
+
+  //$content .= theme('box', t('IP History'), ($posts ? $posts : t('No ip history')));
+  //$content .= $posts;
   // Get recent posts.
   $posts = NULL;
   $rows = array();
-  $result = db_query_range("SELECT * FROM {node} WHERE uid = :uid ORDER BY created DESC", array(':uid' => $uid), 0, 5);
-  while ($node = $result->fetchObject()) {
+  $result = db_query("SELECT * FROM {node} n WHERE n.uid = :uid ORDER BY n.created DESC", array(':uid' => $u->uid));
+  foreach ($result as $node) {
     $rows[] = array(l($node->title, "node/$node->nid") . ' ' . theme('mark', node_mark($node->nid, $node->changed)), $node->type, date('M d, Y', $node->created), ($node->status ? t('published') : t('not published')));
   }
   if ($rows) {
     $pheader = array(t('Title'), t('Type'), t('Created'), t('Status'));
-    $posts = theme('table', $pheader, $rows);
+    $posts = theme('table', array('header' => $pheader, 'rows' => $rows));
   }
 
-  $content .= theme('box', t('Recent Posts'), ($posts ? $posts : t('No recent posts')));
+  //$content .= theme('box', t('Recent Posts'), ($posts ? $posts : t('No recent posts')));
+  //$content .= $posts;
 
   if (module_exists('comment')) {
     // Get recent comments.
     $rows = array();
     $posts = NULL;
 
-    $result = db_query('SELECT cid, nid, subject, changed, timestamp, status FROM {comments} WHERE uid = :uid ORDER BY timestamp DESC', array(':uid' => $uid));
-    while ($comment = $result->fetchObject()) {
-      $rows[] = array(l($comment->subject, 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid)) . ' ' . theme('mark', node_mark($comment->nid, $comment->changed)), date('M d, Y', $comment->timestamp), ($comment->status ? t('not published') : t('published')));
+    $result = db_query('SELECT cid, nid, subject, changed, created, status FROM {comment} c WHERE c.uid = :uid ORDER BY created DESC', array(':uid' => $u->uid));
+    foreach ($result as $comment) {
+      $rows[] = array(
+        l($comment->subject, 'node/' . $comment->nid, array(
+          'fragment' => 'comment-' . $comment->cid,
+        ))
+        . ' '
+        . theme('mark',
+          node_mark($comment->nid, $comment->changed)),
+          date('M d, Y', $comment->timestamp),
+          ($comment->status ? t('not published') : t('published')
+        )
+      );
     }
 
-    if ($rows) {
-      $cheader = array(t('Subject'), t('Date Created'), t('Status'));
-      $posts = theme('table', $cheader, $rows);
-    }
-    $content .= theme('box', t('Recent Comments'), ($posts ? $posts : t('No recent comments')));
+    $cheader = array(t('Subject'), t('Date Created'), t('Status'));
+    //$content .= theme('box', t('Recent Comments'), ($posts ? $posts : t('No recent comments')));
+    $build['pager_table1'] = array(
+      '#theme' => 'table',
+      '#header' => $cheader,
+      '#rows' => $rows,
+      '#empty' => t("No comments found"),
+    );
+
+    // Attach the pager theme.
+    $build['pager_pager1'] = array('#theme' => 'pager');
   }
-  return $content;
+  return $build;
 }
 
+/**
+ * Implements hook_form().
+ */
 function troll_dnsbl_settings() {
   $form = array();
 
   $form['troll_dnsbl_ip_test'] = array(
     '#type' => 'markup',
-     '#value' => l(t('IP test'), 'admin/user/troll/dnsbl/test'),
+    '#value' => l(t('IP test'), 'admin/people/troll/dnsbl/test'),
   );
   $form['troll_dnsbl_active'] = array(
     '#type' => 'checkbox',
     '#title' => t('Enable Operations'),
-    '#default_value' => variable_get('troll_dnsbl_active', 0)
+    '#default_value' => variable_get('troll_dnsbl_active', 0),
   );
+  $dnsbl = _troll_dnsbl_default_servers();
+  array_unshift($dnsbl, t('-Select-'));
   $form['troll_dnsbl_list'] = array(
-    '#type' => 'textarea',
+    '#type' => 'select',
     '#title' => t('Servers to query'),
-    '#default_value' => _troll_dnsbl_default_servers(),
-    '#description' => t('DNS servers to query. Each on a separate line.')
+    '#default_value' => variable_get('troll_dnsbl_list', 0),
+    '#description' => t('Use the crtl key for multiple server selection.'),
+    '#options' => $dnsbl,
+    '#multiple' =>TRUE,
   );
   $form['troll_dnsbl_threshold'] = array(
     '#type' => 'select',
@@ -1078,6 +1232,9 @@ function troll_dnsbl_settings() {
   return system_settings_form($form);
 }
 
+/**
+ * Implements hook_form().
+ */
 function troll_dnsbl_test_form() {
   $form = array();
 
@@ -1090,7 +1247,7 @@ function troll_dnsbl_test_form() {
 
   $form['submit'] = array(
     '#type' => 'submit',
-    '#value' => t('Test')
+    '#value' => t('Test'),
   );
 
   $form['#redirect'] = FALSE;
@@ -1098,6 +1255,9 @@ function troll_dnsbl_test_form() {
   return $form;
 }
 
+/**
+ * Submit handler for dnsbl test form.
+ */
 function troll_dnsbl_test_form_submit($form, &$form_state) {
 
   if (_troll_dnsbl_blacklisted($form_state['values']['ip'])) {
@@ -1108,4 +1268,3 @@ function troll_dnsbl_test_form_submit($form, &$form_state) {
   }
   drupal_set_message($message);
 }
-
diff --git a/troll.info b/troll.info
index 1211fc1..9d3173f 100644
--- a/troll.info
+++ b/troll.info
@@ -4,4 +4,9 @@ description = Provides tools for community sites including users by IP address,
 core = 7.x
 files[] = troll.install
 files[] = troll.module
-files[] = troll.admin.inc
\ No newline at end of file
+files[] = troll.admin.inc
+; Information added by drupal.org packaging script on 2010-11-12
+version = "HEAD"
+project = "troll"
+datestamp = "1289564581"
+
diff --git a/troll.module b/troll.module
index c72594a..ed4ad9d 100644
--- a/troll.module
+++ b/troll.module
@@ -12,7 +12,7 @@
  */
 
 /**
- * Implementation of hook_boot().
+ * Implements hook_boot().
  */
 function troll_boot() {
   if (troll_is_blacklisted()) {
@@ -22,16 +22,18 @@ function troll_boot() {
         case 'blank':
           exit;
           break;
+
         case '404':
           // drupal_not_found() can make a mess in admin logs with watchdog()
-          drupal_set_header('HTTP/1.0 404 Not Found');
+          drupal_add_http_header('HTTP/1.0 404 Not Found');
           drupal_set_title(t('Page not found'));
-          print theme('page', '');
           exit;
           break;
+
         case 'redirect':
+
           // The default value of troll_blacklist_alt_url should not be an
-          // empty string because then we redirect to ourselves; so use 127.0.0.1.
+          // empty string because then we redirect to ourselves; use 127.0.0.1.
           header('Location: ' . variable_get('troll_blacklist_alt_url', 'http://127.0.0.1'));
           exit;
           break;
@@ -41,10 +43,10 @@ function troll_boot() {
     $req_mod = variable_get('troll_blacklist_mod_requests', 0);
     if ($req_mod == 'notice_post_drop' && !empty($_POST)) {
       $_POST = array();
-      include_once('includes/common.inc');
+      include_once 'includes/common.inc';
       drupal_set_message(t('Your data submission was ignored because you are visiting from a blacklisted location.'), 'warning');
     }
-    else if ($req_mod == 'silent_post_drop') {
+    elseif ($req_mod == 'silent_post_drop') {
       $_POST = array();
     }
 
@@ -75,20 +77,20 @@ function troll_boot() {
           'uid' => $user->uid,
           'ip_address' => ip_address(),
           'created' => REQUEST_TIME,
-          'accessed' => REQUEST_TIME
+          'accessed' => REQUEST_TIME,
         ))
         ->execute();
     }
   }
 
   if (variable_get('troll_enable_ip_ban', 1)) {
-    $ban = db_query('SELECT COUNT(ip_address) FROM {troll_ip_ban} WHERE (expires > :expires OR expires = 0) AND ip_address = :ip_address', array(':expires' => time(), ':ip_address' => ip_address()))->fetchField();
+    $ban = db_query('SELECT COUNT(ip_address) FROM {troll_ip_ban} WHERE (expires > :expires OR expires = 0) AND ip_address = :ip_address', array(':expires' => REQUEST_TIME, ':ip_address' => ip_address()))->fetchField();
     if (!empty($ban->ip_address)) {
       global $base_url;
       watchdog('troll', 'IP Ban: !addr', array('!addr' => ip_address()), WATCHDOG_NOTICE);
       $troll_ip_ban_redirect = variable_get('troll_ip_ban_redirect', '');
       if (empty($troll_ip_ban_redirect)) {
-        include_once('includes/common.inc');
+        include_once 'includes/common.inc';
         $page = drupal_get_path('module', 'troll') . '/blocked.html';
       }
       else {
@@ -101,176 +103,193 @@ function troll_boot() {
 }
 
 /**
- * Implementation of hook_help().
+ * Implements hook_help().
  */
 function troll_help($path, $arg) {
   switch ($path) {
-    case 'admin/user/troll/ip_ban':
+    case 'admin/people/troll/ip_ban':
       if (!variable_get('troll_enable_ip_ban', 1)) {
-        return '<div class="messages error">' . t('IP banning is currently disabled. You can enable it in the !settings page.', array('!settings' => l(t('settings'), 'admin/user/troll/settings')));
+        return '<div class="messages error">' . t('IP banning is currently disabled. You can enable it in the !settings page.', array('!settings' => l(t('settings'), 'admin/people/troll/settings')));
       }
       break;
   }
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
-function troll_perm() {
+function troll_permission() {
   return array(
     'administer troll' => array(
       'title' => t('Administer Troll'),
-      'description' => t('Set which IP addresses are blocked or whitelisted and which blacklists to use.')
-    )
+      'description' => t('Set which IP addresses are blocked or whitelisted and which blacklists to use.'),
+    ),
   );
 }
 
 /**
- * Implementation of hook_menu().
- *
- * @return array
+ * Implements hook_menu().
  */
 function troll_menu() {
-  $items['admin/user/troll'] = array(
+  $items['admin/people/troll'] = array(
     'title' => 'Troll',
     'description' => 'Manage visitor IP banning.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_search_form'),
     'access arguments' => array('administer troll'),
-    'weight' => 0
+    'file' => 'troll.admin.inc',
+    'weight' => 0,
   );
-  $items['admin/user/troll/search'] = array(
+  $items['admin/people/troll/search'] = array(
     'title' => 'Search Users',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_search_form'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'access arguments' => array('administer troll'),
-    'weight' => 0
+    'file' => 'troll.admin.inc',
+    'weight' => 0,
   );
-  $items['admin/user/troll/search/view'] = array(
+  $items['admin/people/troll/search/view'] = array(
     'title' => 'Search Users',
     'page callback' => 'troll_search_user_detail',
     'access arguments' => array('administer troll'),
-    'type' => MENU_CALLBACK
+    'file' => 'troll.admin.inc',
+    'type' => MENU_CALLBACK,
   );
-  $items['admin/user/troll/search/block'] = array(
+  $items['admin/people/troll/search/block'] = array(
     'title' => 'Block User',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_confirm_block_user_form'),
     'access arguments' => array('administer troll'),
-    'type' => MENU_CALLBACK
+    'file' => 'troll.admin.inc',
+    'type' => MENU_CALLBACK,
   );
-  $items['admin/user/troll/ip_ban'] = array(
+  $items['admin/people/troll/ip_ban'] = array(
     'title' => 'IP Banning',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_ip_ban'),
     'access arguments' => array('administer troll'),
+    'file' => 'troll.admin.inc',
     'type' => MENU_LOCAL_TASK,
-    'weight' => 1
+    'weight' => 1,
   );
-  $items['admin/user/troll/ip_ban/edit'] = array(
+  $items['admin/people/troll/ip_ban/edit'] = array(
     'title' => 'IP Ban Form',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_ip_ban_form'),
     'access arguments' => array('administer troll'),
-    'type' => MENU_CALLBACK
+    'file' => 'troll.admin.inc',
+    'type' => MENU_CALLBACK,
   );
-  $items['admin/user/troll/ip_ban/user'] = array(
+  $items['admin/people/troll/ip_ban/user'] = array(
     'title' => 'IP Ban Form',
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('troll_confirm_ban_ip_form'),
+    'page arguments' => array('troll_confirm_edit_ban_ip_form'),
     'access arguments' => array('administer troll'),
-    'type' => MENU_CALLBACK
+    'file' => 'troll.admin.inc',
+    'type' => MENU_CALLBACK,
   );
-  $items['admin/user/troll/ip_ban/delete'] = array(
+  $items['admin/people/troll/ip_ban/delete'] = array(
     'title' => 'Remove Ban',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_confirm_delete_ip_form'),
     'access arguments' => array('administer troll'),
-    'type' => MENU_CALLBACK
+    'file' => 'troll.admin.inc',
+    'type' => MENU_CALLBACK,
   );
-  $items['admin/user/troll/ip_blacklist'] = array(
+  $items['admin/people/troll/ip_blacklist'] = array(
     'title' => 'Blacklists',
     'page callback' => 'troll_blacklist_summary',
     'access arguments' => array('administer troll'),
+    'file' => 'troll.admin.inc',
     'type' => MENU_LOCAL_TASK,
-    'weight' => 2
+    'weight' => 2,
   );
-  $items['admin/user/troll/ip_blacklist/summary'] = array(
+  $items['admin/people/troll/ip_blacklist/summary'] = array(
     'title' => 'Summary',
     'page callback' => 'troll_blacklist_summary',
     'access arguments' => array('administer troll'),
+    'file' => 'troll.admin.inc',
     'type' => MENU_DEFAULT_LOCAL_TASK,
-    'weight' => 0
+    'weight' => 0,
   );
-  $items['admin/user/troll/ip_blacklist/punishment'] = array(
+  $items['admin/people/troll/ip_blacklist/punishment'] = array(
     'title' => 'Visitor Punishment',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_blacklist_punishment_form'),
     'access arguments' => array('administer troll'),
+    'file' => 'troll.admin.inc',
     'type' => MENU_LOCAL_TASK,
-    'weight' => 1
+    'weight' => 1,
   );
-  $items['admin/user/troll/ip_blacklist/import'] = array(
+  $items['admin/people/troll/ip_blacklist/import'] = array(
     'title' => 'Import Blacklist',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_blacklist_import_form'),
     'access arguments' => array('administer troll'),
+    'file' => 'troll.admin.inc',
     'type' => MENU_LOCAL_TASK,
-    'weight' => 2
+    'weight' => 2,
   );
-  $items['admin/user/troll/ip_blacklist/search'] = array(
+  $items['admin/people/troll/ip_blacklist/search'] = array(
     'title' => 'Search Blacklisted IPs',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_blacklist_search_form'),
     'access arguments' => array('administer troll'),
+    'file' => 'troll.admin.inc',
     'type' => MENU_LOCAL_TASK,
-    'weight' => 3
+    'weight' => 3,
   );
-  $items['admin/user/troll/ip_blacklist/deleteblack'] = array(
+  $items['admin/people/troll/ip_blacklist/deleteblack'] = array(
     'title' => 'Delete Blacklisted IPs',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_confirm_delete_black_block_form'),
     'access arguments' => array('administer troll'),
-    'type' => MENU_CALLBACK
+    'file' => 'troll.admin.inc',
+    'type' => MENU_CALLBACK,
   );
-  $items['admin/user/troll/ip_blacklist/whitelist'] = array(
+  $items['admin/people/troll/ip_blacklist/whitelist'] = array(
     'title' => 'Whitelist',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_whitelist_form'),
     'access arguments' => array('administer troll'),
+    'file' => 'troll.admin.inc',
     'type' => MENU_LOCAL_TASK,
-    'weight' => 4
+    'weight' => 4,
   );
-  $items['admin/user/troll/ip_blacklist/deletewhite'] = array(
+  $items['admin/people/troll/ip_blacklist/deletewhite'] = array(
     'title' => 'Delete Whitelisted IPs',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_confirm_delete_white_block_form'),
     'access arguments' => array('administer troll'),
-    'type' => MENU_CALLBACK
+    'file' => 'troll.admin.inc',
+    'type' => MENU_CALLBACK,
   );
-  $items['admin/user/troll/dnsbl'] = array(
+  $items['admin/people/troll/dnsbl'] = array(
     'title' => 'DNS Blacklist',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_dnsbl_settings'),
     'access arguments' => array('administer troll'),
+    'file' => 'troll.admin.inc',
+    'type' => MENU_LOCAL_TASK,
     'weight' => 5,
-    'type' => MENU_LOCAL_TASK
   );
-  $items['admin/user/troll/dnsbl/test'] = array(
+  $items['admin/people/troll/dnsbl/test'] = array(
     'title' => 'IP test',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_dnsbl_test_form'),
     'access arguments' => array('administer troll'),
-    'type' => MENU_CALLBACK
+    'file' => 'troll.admin.inc',
+    'type' => MENU_CALLBACK,
   );
-  $items['admin/user/troll/settings'] = array(
+  $items['admin/people/troll/settings'] = array(
     'title' => 'Settings',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('troll_admin_settings'),
     'access arguments' => array('administer site configuration'),
+    'file' => 'troll.admin.inc',
     'type' => MENU_LOCAL_TASK,
-    'weight' => 6
+    'weight' => 6,
   );
   $items['user/%troll_user/troll'] = array(
     'title' => 'Troll Track',
@@ -283,10 +302,22 @@ function troll_menu() {
   return $items;
 }
 
-function troll_user_load($arg) {
-  $user = user_load($arg);
-  if (!empty($user)) {
-    return $user->uid;
+/**
+ * Implements hook_user().
+ */
+function troll_user_load($uid) {
+  if (is_object($uid) && !empty($uid->uid) || is_numeric($uid)) {
+    $account = '';
+    if (is_numeric($uid)) {
+      $account = user_load($uid);
+    }
+    else {
+      $account = user_load($uid->uid);
+      if (!empty($account)) {
+        $uid = $account->uid;
+      }
+    }
+    return $uid;
   }
 }
 
@@ -304,23 +335,26 @@ function _troll_last_ip($uid) {
 }
 
 /**
- * Implementation of hook_comment_view().
+ * Implements hook_comment_view().
  */
 function troll_comment_view(&$comment) {
   $comment->troll_last_ip = _troll_last_ip($comment->uid);
 }
 
 /**
- * Convert dotted decimal IP to long integer and check for validity
+ * Convert dotted decimal IP to long integer and check for validity.
+ *
+ * @param string $ip
+ *   A IP in decimal format
  *
- * @param $ip string
- * @return integer
+ * @return int
+ *   returns the integer value of the IP address
  */
 function _troll_longip($ip) {
   $longip = ip2long($ip);
   if ($longip === FALSE || $longip == -1) {
-    drupal_set_message(t('IP %ip not valid!', array('%ip' => $ip)));
-    drupal_goto('admin/user/troll/ip_blacklist');
+    drupal_set_message(t('IP @ip not valid!', array('@ip' => $ip)));
+    drupal_goto('admin/people/troll/ip_blacklist');
   }
   return $longip;
 }
@@ -328,12 +362,12 @@ function _troll_longip($ip) {
 /**
  * Removes an IP ban from the database.
  */
-function troll_remove_ip($iid) {
+function troll_remove_ip($ip) {
   $deleted = db_delete('troll_ip_ban')
-    ->condition('iid', $iid)
+    ->condition('ip_address', $ip)
     ->execute();
   if ($deleted) {
-    drupal_set_message(t('IP ban removed.'));
+    drupal_set_message(t('!num IP ban has been removed.', $ip));
   }
   else {
     drupal_set_message(t('An error occurred. IP ban not removed.'));
@@ -341,9 +375,12 @@ function troll_remove_ip($iid) {
 }
 
 /**
- * Removes IP block from the blacklist
+ * Removes IP block from the blacklist.
  *
- * @param $edit array
+ * @param int $net
+ *   The int value of the network IP
+ * @param int $bcast
+ *   The integer value of the network IP
  */
 function troll_remove_blacklist($net, $bcast) {
   $deleted = db_delete('troll_blacklist')
@@ -360,14 +397,18 @@ function troll_remove_blacklist($net, $bcast) {
 /**
  * Removes IP block from the whitelist.
  *
- * @param $edit array
+ * @param int $net
+ *   The int value of the network IP
+ * @param int $bcast
+ *   The integer value of the network IP
  */
 function troll_remove_whitelist($net, $bcast) {
   $deleted = db_delete('troll_whitelist')
-    ->condition(db_and()->condition('net', $net)->condition('bcast', $bcast))
+    ->condition(db_and()->condition('net', $net)
+    ->condition('bcast', $bcast))
     ->execute();
   if ($deleted) {
-    drupal_set_message(t('IP whitelist removed.'));
+    drupal_set_message(t('IP whitelist address removed.'));
   }
   else {
     drupal_set_message(t('An error occurred, IP whitelist not removed.'));
@@ -377,7 +418,8 @@ function troll_remove_whitelist($net, $bcast) {
 /**
  * Inserts an IP ban into the database.
  *
- * @param $edit array
+ * @param array $edit
+ *   trolls $edit array values to work with
  */
 function troll_insert_ip($edit) {
   global $user;
@@ -393,7 +435,7 @@ function troll_insert_ip($edit) {
       'domain_name' => $edit['domain_name'],
       'created' => REQUEST_TIME,
       'expires' => $expires,
-      'uid' => $user->uid
+      'uid' => $user->uid,
     ))
     ->execute();
   if ($insert) {
@@ -407,7 +449,8 @@ function troll_insert_ip($edit) {
 /**
  * Updates an IP ban in the database.
  *
- * @param $edit array
+ * @param array $edit
+ *   trolls $edit array values to work with
  */
 function troll_update_ip($edit) {
   global $user;
@@ -418,7 +461,7 @@ function troll_update_ip($edit) {
       'ip_address' => $edit['ip_address'],
       'domain_name' => $edit['domain_name'],
       'expires' => $expires,
-      'uid' => $user->uid
+      'uid' => $user->uid,
     ))
     ->condition('iid', $edit['iid'])
     ->execute();
@@ -443,7 +486,7 @@ function troll_check_ip() {
       ->fields(array(
         'uid' => $user->uid,
         'ip_address' => ip_address(),
-        'created' => REQUEST_TIME
+        'created' => REQUEST_TIME,
       ))
       ->execute();
   }
@@ -452,7 +495,9 @@ function troll_check_ip() {
 /**
  * Checks remote IP to see if it is blacklisted.
  *
- * @return integer zero if whitelisted or not blacklisted, otherwise the number of IP blacklist block matches
+ * @return int
+ *   zero if whitelisted or not blacklisted, otherwise the number of the IP
+ *   blacklist the block matches
  */
 function troll_is_blacklisted() {
   static $blacklisted, $whitelisted;
@@ -466,46 +511,51 @@ function troll_is_blacklisted() {
     return FALSE;
   }
   else {
-    $whitelisted = (bool)db_query_range('SELECT 1 FROM {troll_whitelist} w WHERE w.net <= :longip AND w.bcast >= :longip', array(':longip' => $longip), 0, 1)->fetchField();
+    $whitelisted = (bool) db_query_range('SELECT 1 FROM {troll_whitelist} w WHERE w.net <= :longip AND w.bcast >= :longip', 0, 1, array(':longip' => $longip))->fetchField();
     if ($whitelisted) {
       return FALSE;
     }
-    return (bool)db_query_range('SELECT 1 FROM {troll_blacklist} b WHERE b.net <= :longip AND b.bcast >= :longip', array(':longip' => $longip), 0, 1)->fetchField();
+    return (bool) db_query_range('SELECT 1 FROM {troll_blacklist} b WHERE b.net <= :longip AND b.bcast >= :longip', 0, 1, array(':longip' => $longip))->fetchAll();
   }
 }
 
 /**
  * Bans a user.
  *
- * @param $uid int
+ * @param int $uid
+ *   User ID to block
  */
 function troll_block_user($uid) {
-  // block them
+  // Block them.
   $user_edit['status'] = 0;
-  // remove all their permissions roles
+  // Remove all their permission roles.
   $user_edit['roles'] = array();
   $user = user_load($uid);
   user_save($user, $user_edit);
-  sess_destroy_uid($uid);
 
   if (variable_get('troll_block_role', NULL)) {
-    $name = db_query_range('SELECT name FROM {users} WHERE uid = :uid', array(':uid' => $uid), 0, 1)->fetchField();
-    $role = db_query_range('SELECT name FROM {role} WHERE rid = :rid', array(':rid' => variable_get('troll_block_role', 0)), 0, 1)->fetchField();
+    $name = db_query_range('SELECT name FROM {users} WHERE uid = :uid', 0, 1, array(':uid' => $uid))->fetchField();
+    $role = db_query_range('SELECT name FROM {role} WHERE rid = :rid', 0, 1, array(':rid' => variable_get('troll_block_role', 0)))->fetchField();
     db_insert('users_roles')
       ->fields(array(
         'uid' => $uid,
-        'rid' => variable_get('troll_block_role', '0')
-      ))
-      ->execute();
-    drupal_set_message(t('Blocked user !link and assigned role %role.', array('!link' => l($name, "admin/user/troll/search/view/$uid"), '%role' => $role)));
+        'rid' => variable_get('troll_block_role', '0'),
+      )
+    )->execute();
+    drupal_set_message(t('Blocked user !link and assigned role %role.', array(
+      '!link' => l($name, "admin/people/troll/search/view/$uid"),
+      '%role' => $role,
+    )));
   }
   else {
-    drupal_set_message(t('Blocked user !link.', array('!link' => l($name, "admin/user/troll/search/view/$uid"))));
+    drupal_set_message(t('Blocked user !link.', array(
+      '!link' => l($name, "admin/people/troll/search/view/$uid"),
+    )));
   }
 }
 
 /**
- * Implementation of hook_comment().
+ * Implements hook_comment().
  */
 function troll_comment($comment, $op) {
   if (variable_get('troll_dnsbl_active', 0) != 1) {
@@ -515,7 +565,7 @@ function troll_comment($comment, $op) {
   switch ($op) {
     case 'insert':
     case 'update':
-      $comment = (object)$comment;
+      $comment = (object) $comment;
 
       $ip = ip_address();
       $blacklisted = _troll_dnsbl_blacklisted($ip);
@@ -525,12 +575,13 @@ function troll_comment($comment, $op) {
         $query = $operation['unpublish'][1];
         db_query($query, $comment->cid);
         drupal_set_message(t('Your comment has been queued for moderation by site administrators and will be published after approval.'));
-        watchdog('troll', 'Comment unpublished for DNSBL: %subject.', array('%subject' => $comment->subject), WATCHDOG_INFO, l(t('view'), 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid)));
+        watchdog('troll', 'Comment unpublished for DNSBL: %subject.', array('%subject' => $comment->subject), WATCHDOG_INFO, l(t('view'), 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid)));
       }
       else {
-        watchdog('troll', 'IP %ip is not DNS blacklisted.', array('%ip' => $ip), WATCHDOG_INFO, l(t('view'), 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid)));
+        watchdog('troll', 'IP %ip is not DNS blacklisted.', array('%ip' => $ip), WATCHDOG_INFO, l(t('view'), 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid)));
       }
       return;
+
     default:
       return;
   }
@@ -539,8 +590,11 @@ function troll_comment($comment, $op) {
 /**
  * Check if an IP is blacklisted or not.
  *
- * @param $ip the IP to check.
- * @return true if blacklisted or false
+ * @param string $ip
+ *   the IP to check.
+ *
+ * @return bool
+ *   true if blacklisted or false
  */
 function _troll_dnsbl_blacklisted($ip) {
   $servers = _troll_dnsbl_default_servers();
@@ -549,7 +603,7 @@ function _troll_dnsbl_blacklisted($ip) {
   $threshold = variable_get('troll_dnsbl_threshold', 1);
 
   foreach ($servers as $server) {
-    // we trim because we end up with a new line at the end of each server
+    // We trim because we end up with a new line at the end of each server
     // for an obscure reason!
     if (_troll_dnsbl_check($ip, trim($server))) {
       $threshold--;
@@ -564,14 +618,18 @@ function _troll_dnsbl_blacklisted($ip) {
 }
 
 /**
- * Perform a DNS query
+ * Perform a DNS query.
  *
- * @param $ip the IP to check
- * @param $server the DNS to check.
- * @return true if the entry is there otherise false even if there's an error.
+ * @param string $ip
+ *   the IP to check
+ * @param string $server
+ *   the DNS to check.
+ *
+ * @return bool
+ *   true if the entry is there otherise false even if there's an error.
  */
 function _troll_dnsbl_check($ip, $server) {
-  // Let's reverse the IP
+  // Let's reverse the IP.
   $ip = implode('.', array_reverse(explode('.', $ip)));
 
   $request = implode('.', array($ip, $server));
@@ -579,7 +637,7 @@ function _troll_dnsbl_check($ip, $server) {
   $result = gethostbyname($request);
 
   if ($request == $result) {
-    // No domain
+    // No domain.
     return FALSE;
   }
   else {
@@ -589,16 +647,90 @@ function _troll_dnsbl_check($ip, $server) {
 }
 
 /**
- * Return the list of default DNSBL servers
+ * Return the list of default DNSBL servers.
  *
- * @return the list of default servers.
+ * @return array
+ *   the list of default servers.
  */
 function _troll_dnsbl_default_servers() {
-  return variable_get('troll_dnsbl_list', implode("\n", array(
-    'dnsbl.sorbs.net',
+  return  array(
+    'access.redhawk.org',
+    'b.barracudacentral.org',
+    'bl.shlink.org',
+    'bl.spamcannibal.org',
     'bl.spamcop.net',
-    'dnsbl.njabl.org',
+    'bl.tiopan.com',
+    'blackholes.wirehub.net',
+    'blacklist.sci.kun.nl',
+    'block.dnsbl.sorbs.net',
+    'blocked.hilli.dk',
+    'bogons.cymru.com',
+    'cart00ney.surriel.com',
     'cbl.abuseat.org',
-    'sbl-xbl.spamhaus.org'
-  )));
+    'cblless.anti-spam.org.cn',
+    'dev.null.dk',
+    'dialup.blacklist.jippg.org',
+    'dialups.mail-abuse.org',
+    'dialups.visi.com',
+    'dnsbl.abuse.ch',
+    'dnsbl.ahbl.org',
+    'dnsbl.anticaptcha.net',
+    'dnsbl.antispam.or.id',
+    'dnsbl.dronebl.org',
+    'dnsbl.justspam.org',
+    'dnsbl.kempt.net',
+    'dnsbl.sorbs.net',
+    'dnsbl.tornevall.org',
+    'dnsbl-1.uceprotect.net',
+    'duinv.aupads.org',
+    'dnsbl-2.uceprotect.net',
+    'dnsbl-3.uceprotect.net',
+    'dul.dnsbl.sorbs.net',
+    'dul.ru',
+    'escalations.dnsbl.sorbs.net',
+    'hil.habeas.com',
+    'black.junkemailfilter.com',
+    'http.dnsbl.sorbs.net',
+    'intruders.docs.uu.se',
+    'ips.backscatterer.org',
+    'korea.services.net',
+    'l2.apews.org',
+    'mail-abuse.blacklist.jippg.org',
+    'misc.dnsbl.sorbs.net',
+    'msgid.bl.gweep.ca',
+    'new.dnsbl.sorbs.net',
+    'no-more-funn.moensted.dk',
+    'old.dnsbl.sorbs.net',
+    'opm.tornevall.org',
+    'pbl.spamhaus.org',
+    'proxy.bl.gweep.ca',
+    'psbl.surriel.com',
+    'pss.spambusters.org.ar',
+    'rbl.schulte.org',
+    'rbl.snark.net',
+    'recent.dnsbl.sorbs.net',
+    'relays.bl.gweep.ca',
+    'relays.bl.kundenserver.de',
+    'relays.mail-abuse.org',
+    'relays.nether.net',
+    'rsbl.aupads.org',
+    'sbl.spamhaus.org',
+    'smtp.dnsbl.sorbs.net',
+    'socks.dnsbl.sorbs.net',
+    'spam.dnsbl.sorbs.net',
+    'spam.olsentech.net',
+    'spamguard.leadmon.net',
+    'spamsources.fabel.dk',
+    'tor.ahbl.org',
+    'tor.dnsbl.sectoor.de',
+    'ubl.unsubscore.com',
+    'web.dnsbl.sorbs.net',
+    'xbl.spamhaus.org',
+    'zen.spamhaus.org',
+    'zombie.dnsbl.sorbs.net',
+    'dnsbl.inps.de',
+    'dyn.shlink.org',
+    'rbl.megarbl.net',
+    'bl.mailspike.net',
+  );
 }
