diff --git a/docroot/profiles/drupal_commons/modules/contrib/digests/digests.cron.inc b/docroot/profiles/drupal_commons/modules/contrib/digests/digests.cron.inc
index e7d1b73..b1dc9cb 100644
--- a/docroot/profiles/drupal_commons/modules/contrib/digests/digests.cron.inc
+++ b/docroot/profiles/drupal_commons/modules/contrib/digests/digests.cron.inc
@@ -20,14 +20,14 @@ function _digests_cron() {
   // Step 1: Get users for whom it is after 6PM in their timezone but who have not had a digest sent for this interval.
   $default = $now > $send_time + $default_tz || $now < $send_time + $default_tz - 43200; // whether it's past send_time in the site's default timezone
   $query = "
-    SELECT d.*, u.* /* We need the digests table first here, otherwise users with no digests row have uid = NULL in the results */
+    SELECT u.uid, u.mail, u.created, COALESCE(d.send_interval, 86400) as send_interval, d.last_sent, u.timezone /* We need the digests table first here, otherwise users with no digests row have uid = NULL in the results */
     FROM {users} u
     LEFT JOIN {digests} d
       ON u.uid = d.uid
     WHERE
-      status = 1 AND (                                                  /* user is not blocked */
-        send_interval IS NULL OR                                        /* user has not set their interval */
-        send_interval = 86400                                           /* user's interval is daily */
+      u.status = 1 AND (                                                  /* user is not blocked */
+        d.send_interval IS NULL OR (                                      /* user has not set their interval */
+        d.send_interval = 86400                                           /* user's interval is daily */
         ". (date('w') == 0 ? 'OR send_interval = 604800' : '') ."       /* user's interval is weekly, and it's Sunday */
       ) AND
       %d > COALESCE(last_sent, created) + (COALESCE(send_interval, 86400) - 43200) /* it's been at least (interval - 12 hours) since the last digest email */
@@ -40,7 +40,7 @@ function _digests_cron() {
     if ($default) {
       $query .= "    OR timezone IS NULL /* the user has not set a timezone, fall back to the site default */";
     }
-    $query .= "\n      )";
+    $query .= "\n      ))";
     if (variable_get('digests_limit', 250)) {
       $result = db_query_range($query, $now, $now, $send_time, $now, $send_time, 0, variable_get('digests_limit', 250));
     }
@@ -56,7 +56,7 @@ function _digests_cron() {
       $result = db_query($query, $now);
     }
   }
-
+  
   // Step 2: For each selected user, collect all activity that has been updated between 6PM 2 days ago and 6PM yesterday
   while ($account = db_fetch_object($result)) {
     if (empty($account) || empty($account->uid) || !valid_email_address($account->mail)) {
@@ -91,7 +91,7 @@ function _digests_cron() {
       WHERE
         display_type = 'email' AND
         stream_owner_type = 'user' AND
-        stream_owner_id = %d AND
+        stream_owner_id = %d AND 
         last_updated > %d /* 2 days ago */ AND
         last_updated < %d /* 1 day ago */ AND (
           viewer_id = %d /* account */ OR
@@ -123,72 +123,68 @@ function _digests_cron() {
           }
         }
       }
-      if (empty($aids)) {
-        continue;
-      }
-      $nids_result = db_query("SELECT aid, target_id AS nid FROM {activity_log_events} WHERE aid IN (". db_placeholders($aids) .")", $aids);
-      $nids = array();
-      while ($node = db_fetch_object($nids_result)) {
-        $nids[$node->aid] = $node->nid;
-      }
-      // If we're not dealing with any nodes, we don't need to check node access.
-      if (empty($nids)) {
-        continue;
+      // Perform db_rewrite_sql on messages about nodes, where applicable.
+      if (!empty($aids)) {
+        $nids_result = db_query("SELECT aid, target_id AS nid FROM {activity_log_events} WHERE aid IN (". db_placeholders($aids) .")", $aids);
+        $nids = array();
+        while ($node = db_fetch_object($nids_result)) {
+          $nids[$node->aid] = $node->nid;
+        }
+        // If we're not dealing with any nodes, we don't need to check node access.
+        if (empty($nids)) {
+          continue;
+        }
+        // Reduce the list of nids returned by the view to those which the user has permission to view.
+        $nids_visible = array();
+        $query_restricted = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n WHERE nid IN (". db_placeholders($nids) .")"), array_values($nids));
+        while ($result_restricted = db_fetch_object($query_restricted)) {
+          $nids_visible[$result_restricted->nid] = $result_restricted->nid;
+        }
+        $nids_to_remove = array_diff($nids, $nids_visible); // preserves keys
+        // Remove the activity from $messages that use events related to restricted nodes.
+        $result_keys_to_remove = array();
+        foreach ($nids_to_remove as $aid => $nid) {
+          $key = $aid_to_result_key_map[$aid];
+          $result_keys_to_remove[$key] = $key;
+        }
+        $messages = array_diff_key($messages, $result_keys_to_remove);
       }
-      // Reduce the list of nids returned by the view to those which the user has permission to view.
-      $nids_visible = array();
-      $query_restricted = db_query(db_rewrite_sql("SELECT DISTINCT(n.nid) FROM {node} n WHERE nid IN (". db_placeholders($nids) .")"), array_values($nids));
-      while ($result_restricted = db_fetch_object($query_restricted)) {
-        $nids_visible[$result_restricted->nid] = $result_restricted->nid;
+      $output = theme('digests_email', $account, $messages, $now);
+      // Step 4: Pass the rendered activity stream to the Mime Mail module for delivery
+      if ($interval == 86400) {
+        $subject = t('Your @site activity for @date', array(
+          '@site' => variable_get('site_name', 'Drupal'),
+          '@date' => date('l, F j', $now - $interval),
+        ));
       }
-      $nids_to_remove = array_diff($nids, $nids_visible); // preserves keys
-      // Remove the activity from $messages that use events related to restricted nodes.
-      $result_keys_to_remove = array();
-      foreach ($nids_to_remove as $aid => $nid) {
-        $key = $aid_to_result_key_map[$aid];
-        $result_keys_to_remove[$key] = $key;
+      elseif ($interval == 604800) {
+        $subject = t('Your @site activity for the week of @date', array(
+          '@site' => variable_get('site_name', 'Drupal'),
+          '@date' => date('F j', $now - $interval),
+        ));
       }
-      $messages = array_diff_key($messages, $result_keys_to_remove);
-    }
-    if (empty($messages)) {
-      continue;
-    }
-    $output = theme('digests_email', $account, $messages, $now);
-
-    // Step 4: Pass the rendered activity stream to the Mime Mail module for delivery
-    if ($interval == 86400) {
-      $subject = t('Your @site activity for @date', array(
-        '@site' => variable_get('site_name', 'Drupal'),
-        '@date' => date('l, F j', $now - $interval),
-      ));
-    }
-    elseif ($interval == 604800) {
-      $subject = t('Your @site activity for the week of @date', array(
-        '@site' => variable_get('site_name', 'Drupal'),
-        '@date' => date('F j', $now - $interval),
-      ));
-    }
-    mimemail(
-      variable_get('site_mail', ini_get('sendmail_from')), //sender
-      $account, // recipient
-      $subject, // subject
-      $output,  // HTML for body
-      NULL,     // force plaintext only
-      array(),  // headers
-      NULL,     // custom plaintext version
-      array(),  // attachments
-      'digests' // mailkey
-    );
-
-    // Step 5: Update the "last sent" time for each processed user
-    db_query("UPDATE {digests} SET last_sent = %d WHERE uid = %d", $now, $account->uid);
-    if (db_affected_rows() <= 0) {
-      $insert = (object) array(
-        'uid' => $account->uid,
-        'last_sent' => $now,
-        'send_interval' => 86400,
+      mimemail(
+        variable_get('site_mail', ini_get('sendmail_from')), //sender
+        $account, // recipient
+        $subject, // subject
+        $output,  // HTML for body
+        NULL,     // force plaintext only
+        array(),  // headers
+        NULL,     // custom plaintext version
+        array(),  // attachments
+        'digests' // mailkey
       );
-      drupal_write_record('digests', $insert);
+  
+      // Step 5: Update the "last sent" time for each processed user
+      db_query("INSERT INTO {digests} (uid, last_sent, send_interval) VALUES (SET last_sent = %d WHERE uid = %d", $now, $account->uid);
+      if (db_affected_rows() <= 0) {
+        $insert = (object) array(
+          'uid' => $account->uid,
+          'last_sent' => $now,
+          'send_interval' => 86400,
+        );
+        drupal_write_record('digests', $insert);
+      }
     }
   }
 }
