diff --git a/php_errors.info b/php_errors.info
index cceaf9c..5f56f9b 100644
--- a/php_errors.info
+++ b/php_errors.info
@@ -1,22 +1,6 @@
-; $Id: php_errors.info,v 1.8 2010/07/07 18:26:56 ptalindstrom Exp $
 name = PHP Errors
 description = Admin tool to help monitor PHP errors which occur on the site.
 package = Administration
-version = 6.x-1.0
 dependencies[] = token
 dependencies[] = cronplus
-
 core = 6.x
-; Information added by drupal.org packaging script on 2010-02-17
-version = "6.x-1.0"
-core = "6.x"
-project = "php_errors"
-datestamp = "1266446708"
-
-
-; Information added by drupal.org packaging script on 2010-11-08
-version = "6.x-1.3"
-core = "6.x"
-project = "php_errors"
-datestamp = "1289187946"
-
diff --git a/php_errors.install b/php_errors.install
index 449fe7c..d60d848 100644
--- a/php_errors.install
+++ b/php_errors.install
@@ -1,6 +1,8 @@
 <?php
-// $Id: php_errors.install,v 1.6 2010/02/17 22:41:24 ptalindstrom Exp $  
-
+/**
+ * @file
+ * Provide installation data for php_errors.module
+ */
 
 /**
  * Implementation of hook_schema().
@@ -36,7 +38,7 @@ function php_errors_schema() {
 function php_errors_install() {
   // Create tables.
   drupal_install_schema('php_errors');
-  drupal_set_message(t('The table for the PHP Errors archive has been created successfully.'));
+  drupal_set_message(st('The table for the PHP Errors archive has been created successfully.'));
 }
 
 /**
@@ -49,12 +51,10 @@ function php_errors_uninstall() {
   // remove variables
   $result = update_sql("DELETE FROM {variable} WHERE name like 'php_errors_%'");
 
-  
   if ($result['success']) {
-    drupal_set_message('The PHP Errors module was successfully uninstalled.');
+    drupal_set_message(t('The PHP Errors module was successfully uninstalled.'));
   }
   else {
-    drupal_set_message('There was an error removing the php_errors_archive table.', 'error');
+    drupal_set_message(t('There was an error removing the php_errors_archive table.'), 'error');
   }
 }
-
diff --git a/php_errors.module b/php_errors.module
index aa4da37..bf670b8 100644
--- a/php_errors.module
+++ b/php_errors.module
@@ -1,38 +1,34 @@
 <?php
-// $Id: php_errors.module,v 1.9 2010/11/08 03:43:06 ptalindstrom Exp $   
-                                                                                                     
 
 /**
  * Implementation of hook_help().
- */    
+ */
 function php_errors_help($path='', $arg) {
   switch ($path) {
     case 'admin/modules#description':
-      return t("This module helps to manage your site's PHP Errors. It performs 3 functions: it provides a summary page of the 
-      watchdog's PHP errors, it archive's this summary and it may be set to email a summary report to specific email addresses 
-      or roles.");
+      return '<p>' . t("This module helps to manage your site's PHP Errors. It performs 3 functions: it provides a summary page of the watchdog's PHP errors, it archive's this summary and it may be set to email a summary report to specific email addresses or roles.") . '</p>';
   }
 }
 
 /**
-* Implementation of hook_menu()
-*/
+ * Implementation of hook_menu().
+ */
 function php_errors_menu() {
   $items = array();
-    
+
   // Various Sub-tabs for PHP Error report formats and archive listing
   $items['admin/reports/php_errors'] = array(
     'title' => 'PHP Errors',
     'page callback' => '_php_errors_show',
     'access arguments' => array('administer site configuration'),
     'type' => MENU_NORMAL_ITEM,
-  );        
+  );
   $items['admin/reports/php_errors/summary'] = array(
     'title' => 'Detail',
     'weight' => -5,
     'access arguments' => array('administer site configuration'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
-  );        
+  );
   $items['admin/reports/php_errors/links'] = array(
     'title' => 'Links Only',
     'weight' => -4,
@@ -40,7 +36,7 @@ function php_errors_menu() {
     'page arguments' => array('links'),
     'access arguments' => array('administer site configuration'),
     'type' => MENU_LOCAL_TASK,
-  );      
+  );
   $items['admin/reports/php_errors/archive'] = array(
     'title' => 'Archive',
     'weight' => -3,
@@ -49,7 +45,7 @@ function php_errors_menu() {
     'access arguments' => array('administer site configuration'),
     'type' => MENU_LOCAL_TASK,
   );
-  
+
   // Admin settings
   $items['admin/settings/php_errors'] = array(
     'title' => 'PHP Errors',
@@ -62,8 +58,8 @@ function php_errors_menu() {
 
   $items['admin/reports/php_errors/archive/%php_errors_archive_id'] = array(
     'title' => 'Archive',
-    'page callback' => '_php_errors_archive_view',   
-    'page arguments' => array('php_errors_archive_id', 4),  
+    'page callback' => '_php_errors_archive_view',
+    'page arguments' => array('php_errors_archive_id', 4),
     'access arguments' => array('administer site configuration'),
     'type' => MENU_LOCAL_TASK,
   );
@@ -71,9 +67,11 @@ function php_errors_menu() {
   return $items;
 }
 
-
+/**
+ * Menu callback - admin settings form.
+ */
 function php_errors_admin_settings() {
-  // system settings     
+  // system settings
   $form['php_errors_notify_addresses'] = array(
     '#type' => 'textfield',
     '#title' => t('Admin Notification Email Addresses'),
@@ -81,36 +79,36 @@ function php_errors_admin_settings() {
     '#description' => t("Comma separated list of email addresses to send PHP Error summary report to."),
   );
   $form['php_errors_notify_roles'] = array(
-    '#type' => 'checkboxes', 
+    '#type' => 'checkboxes',
     '#title' => t('Notification Role'),
     '#options' => user_roles(true),
     '#default_value' => variable_get('php_errors_notify_roles', array()),
     '#description' => t("Defines roles which will be sent the PHP Error summary report."),
-  );          
+  );
   $form['php_errors_notify_frequency'] = array(
-    '#type' => 'radios',   
+    '#type' => 'radios',
     '#title' => t('Frequency of Notification'),
     '#options' => array(0 => 'never', 1 => 'daily', 2 => 'weekly', 3 => 'monthly'),
     '#default_value' => variable_get('php_errors_notify_frequency', 2),
     '#description' => t("Select how often email error reports will be sent. NOTE: archiving is done weekly, regardless of this setting."),
-  ); 
+  );
 
   return system_settings_form($form);
 }
 
+/**
+ * Menu callback - show detail of the php error report.
+ */
 function _php_errors_show($type = null) {
   $rows = array();
-  $results = db_query("SELECT count(1) cnt, timestamp ts, message ms, variables v, location 
+  $results = db_query("SELECT COUNT(wid) cnt, timestamp ts, message ms, variables v, location
     FROM watchdog WHERE type = 'php'
     GROUP by MID(v, 62, 30) ORDER BY timestamp DESC, cnt DESC");
-  
+
   // and if results - lets print them out in a nice table
-  if ($type == 'links') {        
-    $header = array(
-       array('data' => t('Count')),
-       array('data' => t('Location')),
-    );         
-    while ($result = db_fetch_object($results)) {           
+  if ($type == 'links') {
+    $header = array(t('Count'), t('Location'));
+    while ($result = db_fetch_object($results)) {
       $row = array();
       $row[] = $result->cnt;
       $row[] = $result->location;
@@ -118,19 +116,14 @@ function _php_errors_show($type = null) {
     }
   }
   else {
-    $header = array(
-      array('data' => t('Count')),
-      array('data' => t('Date')),
-      array('data' => t('Error')),
-      array('data' => t('Location')),
-    );    
-    while ($result = db_fetch_object($results)) {           
+    $header = array(t('Count'), t('Date'), t('Error'), t('Location'));
+    while ($result = db_fetch_object($results)) {
       $variables = unserialize($result->v);
-      $error = str_replace(array('%message', '%file', '%line'), array($variables['%message'], $variables['%file'], $variables['%line']), "%message in %file on line %line.");   
+      $error = t("%message in %file on line %line.", $variables);
       $row = array();
       $row[] = $result->cnt;
       $row[] = date("m-d-Y", $result->ts);
-      $row[] = wordwrap(html_entity_decode($error), 60, "<br>", 1);
+      $row[] = wordwrap(html_entity_decode($error), 60, "<br />", 1);
       $row[] = $result->location;
       $rows[] = $row;
     }
@@ -139,41 +132,44 @@ function _php_errors_show($type = null) {
   return theme('table', $header, $rows);
 }
 
+/**
+ * Helper function for email report.
+ */
 function _php_errors_email() {
-  $results = db_query("SELECT count(1) cnt, timestamp ts, message ms, location 
+  $results = db_query("SELECT COUNT(wid) cnt, timestamp ts, message ms, location
     FROM watchdog WHERE type = 'php'
     GROUP by LEFT(ms, 30) ORDER BY timestamp DESC, cnt DESC");
-  
+
   // and if results - lets format them as a table for a txt email
-  $header = sprintf("\n\n%-10s %-20s %-55s \n", t('Count'), t('Date'), t('Location')) .t('Error'); 
+  $header = sprintf("\n\n%-10s %-20s %-55s \n", t('Count'), t('Date'), t('Location')) . t('Error');
   $header .= "\n--------------------------------------------------------------------------------\n\n";
 
   $rows = "";
-  while ($result = db_fetch_object($results)) {           
-    $rows .= sprintf("%-10s %-20s %-55s \n", 
-      $result->cnt, 
-      date("m-d-Y", $result->ts), 
+  while ($result = db_fetch_object($results)) {
+    $rows .= sprintf("%-10s %-20s %-55s \n",
+      $result->cnt,
+      date("m-d-Y", $result->ts),
       $result->location
     );
     $rows .= strip_tags(html_entity_decode($result->ms, ENT_QUOTES)) ."\n\n";
   }
-  
-  $preamble = "The following is this weeks PHP Error Summary Report.\n\nRegards,\n\n" . variable_get('site_name', 'Your Site'); 
-  
+
+  $preamble = t("The following is this weeks PHP Error Summary Report.") . "\n\n";
+  $preamble .= t("Regards,\n\n@sitename", array('@sitename' => variable_get('site_name', t('Your Site'))));
+
   return $preamble . $header . $rows;
 }
 
+/**
+ * Menu callback - show list of archived PHP reports.
+ */
 function _php_errors_show_archive() {
   $results = db_query("SELECT * FROM {php_errors_archive} ORDER BY created DESC");
-  
-  $header = array(
-    array('data' => t('Archived Reports')),
-    array(''=>""),
-    array(''=>""),
-    array(''=>"")
-  ); 
-  
-  $row = 1; $col = 1;
+
+  $header = array(t('Archived Reports'), '',  '', '');
+
+  $row = 1;
+  $col = 1;
   while ($report = db_fetch_object($results)) {
     if ($col > 4) {
       $col = 1;
@@ -182,24 +178,30 @@ function _php_errors_show_archive() {
     $reports[$row][$col] = l(date("M d, Y", $report->created), "admin/reports/php_errors/archive/". $report->rid);
     $col++;
   }
-  
+
   // fill out other columns with blanks to improve look
   for ($c = $col; $c < 5; $c++) {
     $reports[$row][$c] = "";
   }
-  
+
   return theme('table', $header, $reports);
 }
 
-// Show an archived report
+/**
+ * Show an archived report.
+ */
 function _php_errors_archive_view($rid) {
-  $report =  db_fetch_object(db_query("SELECT * FROM {php_errors_archive} WHERE rid = %d", $rid));  
-  
-  drupal_set_title(t("PHP Errors") ." - <em>Archived Report for: ". date("M d, Y", $report->created) ."</em>");
-  
-  $output = '<input onclick="location.href=\''. url("admin/reports/php_errors/archive") .'\'" type="submit" class="form-submit" value="Return to Archive" id="edit-submit"/>';
-  $output .= "<br><br>". $report->report;
-  
+  $output = '<input onclick="location.href=\''. url("admin/reports/php_errors/archive") .'\'" type="submit" class="form-submit" value="' . t('Return to Archive') . '" id="edit-submit"/>';
+
+  if ($report =  db_fetch_object(db_query("SELECT * FROM {php_errors_archive} WHERE rid = %d", $rid))) {
+    drupal_set_title(t('PHP Errors - Archived report for: %date', array('%date' => date('M d, Y', $report->created))));
+    $output .= "<br /><br />";
+    $output .= $report->report;
+  }
+  else {
+    drupal_set_message(t("The report wasn't found."), 'warning');
+  }
+
   return $output;
 }
 
@@ -207,47 +209,75 @@ function _php_errors_archive_view($rid) {
 *     - send email notifications to selected users (frequency based on frequency setting)
 *     - archive the error report (weekly)
 */
+
+/**
+ * Implements hook_cronplus_daily().
+ */
 function php_errors_cronplus_daily($now, $last_cron, $last_this) {
-  if (variable_get('php_errors_notify_frequency', 0) == 1) _php_errors_send_notifications();
+  if (variable_get('php_errors_notify_frequency', 0) == 1) {
+    _php_errors_send_notifications();
+  }
 }
+
+/**
+ * Implements hook_cronplus_weekly().
+ */
 function php_errors_cronplus_weekly($now, $last_cron, $last_this) {
-  if (variable_get('php_errors_notify_frequency', 2) == 2) _php_errors_send_notifications();    // default to weekly if not set
-  
+  // default to weekly if not set
+  if (variable_get('php_errors_notify_frequency', 2) == 2) {
+    _php_errors_send_notifications();
+  }
+
   // archive the report
   $report = _php_errors_show();
-  db_query("INSERT INTO {php_errors_archive} (report, created) VALUES ('%s', %d)", $report, time()); 
-}   
+  db_query("INSERT INTO {php_errors_archive} (report, created) VALUES ('%s', %d)", $report, time());
+}
+
+/**
+ * Implements hook_cronplus_monthly().
+ */
 function php_errors_cronplus_monthly($now, $last_cron, $last_this) {
-  if (variable_get('php_errors_notify_frequency', 0) == 3) _php_errors_send_notifications();
+  if (variable_get('php_errors_notify_frequency', 0) == 3) {
+    _php_errors_send_notifications();
+  }
 }
 
-// email summary report to selected users 
+/**
+ * Email summary report to selected users.
+ */
 function _php_errors_send_notifications() {
   $site_name = variable_get('site_name', 'Your Site');
-  $params['from'] = "$site_name <". variable_get('site_mail', ini_get('sendmail_from')) .'>';;
-  
+  $params['from'] = "$site_name <". variable_get('site_mail', ini_get('sendmail_from')) .'>';
+
   // pull list of all user in selected roles
   $users = _php_errors_get_roles_emails();
-  
+
   // and add individual csv list of addresses
   // if there are any individual emails address; lets use those
   // if none; lets at least send to site admin
-  if (!$ind_emails = variable_get('php_errors_notify_addresses', '')) $ind_emails = variable_get('site_mail', '');
-  $single_emails = split(",", $ind_emails);
-  if (count($single_emails)) {
+  if (!$ind_emails = variable_get('php_errors_notify_addresses', '')) {
+    $ind_emails = variable_get('site_mail', '');
+  }
+  $single_emails = explode(",", $ind_emails);
+  if (!empty($single_emails)) {
     foreach ($single_emails as $single) {
-      if (valid_email_address(trim($single))) $users[trim($single)] = trim($single);
+      $email_trimmed = trim($single);
+      if (valid_email_address($email_trimmed)) {
+        $users[$email_trimmed] = $email_trimmed;
+      }
     }
   }
   $users = array_unique($users);
-  if (!count($users)) break;
-  
+  if (empty($users)) {
+    return;
+  }
+
   // create single CSV list of addresses
-  foreach ($users as $name => $email) {      
+  foreach ($users as $name => $email) {
     $emails[] = $name . " <". $email .">";
   }
-  $recipients = join(",", $emails);
-  
+  $recipients = implode(",", $emails);
+
   $params['subject'] = t("PHP Error Summary Report");
   $params['body'] = _php_errors_email();
 
@@ -259,26 +289,25 @@ function _php_errors_send_notifications() {
   }
 }
 
-// get array of all email addresses for each user in selected roles
+/**
+ * Return array of all email addresses for each user in selected roles.
+ */
 function _php_errors_get_roles_emails() {
   $emails = array();
-  
-  $roles = variable_get('php_errors_notify_roles', 0);
-  if (!$roles) return;
-  
-  $included = array_filter($roles);
-  
-  if (count($included) > 1) {
-    foreach ($included as $role) $rolesql[] = " ur.rid = $role ";
-    $roles_where = join(" OR ", $rolesql);
+
+  $roles_raw = variable_get('php_errors_notify_roles', 0);
+  if (!empty($roles_raw) && is_array($roles_raw)) {
+    $roles = array_filter($roles_raw);
+    if (!empty($roles)) {
+      $roles_placeholders = db_placeholders($roles);
+      $result = db_query("SELECT u.uid, u.name, u.mail, u.status FROM {users} u
+        INNER JOIN {users_roles} ur ON u.uid = ur.uid
+        WHERE u.status = 1 AND ur.rid IN ($roles_placeholders)", $roles);
+      while ($user = db_fetch_object($result)) {
+        $emails[$user->name] = $user->mail;
+      }
+    }
   }
-  else $roles_where = " ur.rid = ". current($included); 
-  
-  $result = db_query("SELECT u.uid, u.name, u.mail, u.status FROM {users} u
-    INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE $roles_where AND u.status = 1");
-  
-  while ($u = db_fetch_object($result)) $emails[$u->name] = $u->mail;
-  
+
   return $emails;
 }
-
