diff --git a/pift.cron.inc b/pift.cron.inc
index c8f24f7..bcc16c1 100644
--- a/pift.cron.inc
+++ b/pift.cron.inc
@@ -25,6 +25,7 @@ function pift_cron_retest() {
 
     // Loop over 'ON' clause to remove an 'OR' which should be more efficient.
     foreach (array('u.nid = pi.nid', 'cu.nid = pi.nid') as $clause) {
+      // TODO:  UPDATE THIS QUERY (Upload table doesn't exist anymore)
       db_query("UPDATE {pift_test}
                 SET status = :status
                 WHERE type = :type
@@ -188,50 +189,62 @@ function pift_cron_queue_batch_build() {
  * @param array $branches Branches that must be loaded.
  */
 function pift_cron_queue_batch_build_files(array &$batch, array &$branches) {
-  // Load all files that are marked as needs testing or have never been tested.
-  $result = db_query('SELECT f.fid, f.filepath, u.nid AS u_nid, cu.nid AS c_nid, cu.cid AS c_cid
-                      FROM {pift_test} t
-                      JOIN {files} f
-                        ON (t.type = :type AND t.id = f.fid)
-                      LEFT JOIN {upload} u
-                        ON f.fid = u.fid
-                      LEFT JOIN {comment_upload} cu
-                        ON f.fid = cu.fid
-                      WHERE t.status = :status
-                      LIMIT :limit', array(':type' => PIFT_TYPE_FILE, ':status' => PIFT_STATUS_QUEUE, ':limit' => PIFT_XMLRPC_MAX), array('fetch' => PDO::FETCH_ASSOC));
-  foreach ($result as $file) {
-    // Load the issue related to the file, either from the comment or node.
-    $issue_nid = !empty($file['u_nid']) ? $file['u_nid'] : $file['c_nid'];
-    $item = array(
-      'client_identifier' => $file['fid'],
-      'file_url' => file_create_url($file['filepath']),
-    );
 
+  // Retrieve all file tests which are marked as needs testing.
+  $query = db_select('pift_test', 't', array('fetch' => PDO::FETCH_ASSOC))
+    ->fields('t', array('test_id', 'id'))
+    ->condition('type', 2, '=')
+    ->condition('status', 1, '=')
+    ->orderBy('id', 'DESC');
+  $result = $query->execute();
+  $tests = array();
+  foreach ($result as $record) {
+    $tests[$record['test_id']] = $record['id'];
+  }
 
-    $branch_info_result = db_query('SELECT prn.nid AS rid, prn.version_major, prn.tag
-                             FROM {project_issues} pi, {project_release_nodes} prn
-                             WHERE pi.nid = :nid AND pi.rid = :rid', array(':nid' => $issue_nid, ':rid' => prn . nid), array('fetch' => PDO::FETCH_ASSOC));
+  // Retrieve the associated project_issue node for each test.
+  $query = new EntityFieldQuery();
+  $query->entityCondition('entity_type', 'node')
+    ->entityCondition('bundle', 'project_issue')
+    ->propertyCondition('status', 1)
+    ->fieldCondition('field_issue_files', 'fid', $tests, 'IN');
+  $result = $query->execute();
+
+  // Load the project_issue entities
+  if (isset($result['node'])) {
+    $issue_nids = array_keys($result['node']);
+    $issues = entity_load('node', $issue_nids);
+  }
 
-    $item['branch_identifier'] = $branch_info_result['rid'];
-    // Store branch as needed to be included with data.
-    $branches[$branch_info_result['rid']] = FALSE; // Do not test unless commit found.
+  // Foreach issue, datafill the file test batch array placeholder item
+  foreach ($issues as $issue) {
+    $pid = $issue->field_project[LANGUAGE_NONE][0]['target_id'];
+    $version = $issue->field_issue_version[LANGUAGE_NONE][0]['value'];
+    $rid = project_release_exists($pid, $version);
+    $item['branch_identifier'] = $rid;
 
-    // Get any dependent branches and add them to the $branches array
-    $branch_dependencies = project_dependency_get_dependencies($branch_info_result['rid'], PROJECT_DEPENDENCY_DEPENDENCY_REQUIRED);
+    // Store the branch as required for the file test to the 'branches' array.
+    // We mark the value 'FALSE' to indicate that we do not need to test this
+    // branch, unless a commit is found on that branch later in processing.
+    $branches[$rid] = FALSE;
+
+    // Add any additional branches which this branch is dependent on
+    $branch_dependencies = project_dependency_get_dependencies($rid, PROJECT_DEPENDENCY_DEPENDENCY_REQUIRED);
     foreach ($branch_dependencies as $dep) {
       $branches[$dep['release_nid']] = FALSE;
     }
 
-    // Generate link to file issue and comment if relevant.
-    if ($file['c_cid']) {
-      $item['link'] = url('node/' . $issue_nid, array('absolute' => TRUE, 'fragment' => 'comment-' . $file['c_cid']));
-    }
-    else {
-      $item['link'] = url('node/' . $issue_nid, array('absolute' => TRUE));
+    // Add each relevant file on this issue to the batch
+    foreach ($issue->field_issue_files[LANGUAGE_NONE] as $file) {
+      if (in_array($file['fid'], $tests)) {
+        // Finish datafilling the placeholder item.
+        $item['client_identifier'] = $file['fid'];
+        $item['file_url'] = file_create_url($file['uri']);
+        $item['link'] = url('node/' . $issue->nid, array('absolute' => TRUE));
+        // Add the placeholder item to the batch.
+        $batch['files'][] = $item;
+      }
     }
-
-    // Add file to batch.
-    $batch['files'][] = $item;
   }
 }
 
@@ -241,12 +254,19 @@ function pift_cron_queue_batch_build_files(array &$batch, array &$branches) {
  * @param array $branches Branches that must be loaded.
  */
 function pift_cron_queue_batch_build_branches(array &$branches) {
-  // Load the branches that are marked as needs testing or have never been tested.
-  $result = db_query('SELECT t.id AS rid
-                      FROM {pift_test} t
-                      WHERE t.type = :type
-                      AND t.status = :status
-                      LIMIT :limit', array(':type' => PIFT_TYPE_RELEASE, ':status' => PIFT_STATUS_QUEUE, ':limit' => PIFT_XMLRPC_MAX), array('fetch' => PDO::FETCH_ASSOC));
+  // Load branches that are marked as needs testing or have never been tested.
+  $result = db_query(
+    'SELECT t.id AS rid
+    FROM {pift_test} t
+    WHERE t.type = :type AND t.status = :status
+    LIMIT :limit',
+    array(
+      ':type' => PIFT_TYPE_RELEASE,
+      ':status' => PIFT_STATUS_QUEUE,
+      ':limit' => PIFT_XMLRPC_MAX
+    ),
+    array('fetch' => PDO::FETCH_ASSOC)
+  );
   foreach ($result as $branch) {
     $branches[$branch['rid']] = TRUE;
   }
@@ -386,14 +406,16 @@ function pift_cron_queue_batch_build_projects(array &$batch, array $projects) {
  * @return array Release NIDs that match.
  */
 function pift_cron_get_release($pid, $tags) {
-  $result = db_query('SELECT nid
-                      FROM {project_release_nodes}
-                      WHERE pid = :pid
-                      AND tag IN (:tags)',
-                      array(':pid' => $pid, ':tags' => $tags));
+  $query = new EntityFieldQuery();
+  $query->entityCondition('entity_type', 'node')
+    ->entityCondition('bundle', 'project_release')
+    ->propertyCondition('status', 1)
+    ->fieldCondition('field_release_project', 'target_id', $pid, '=')
+    ->fieldCondition('field_release_vcs_label', 'value', $tags, 'IN');
+  $result = $query->execute();
   $rids = array();
-  while ($rid = $result->fetchField()) {
-    $rids[] = $rid;
+  if (isset($result['node'])) {
+    $rids = array_keys($result['node']);
   }
   return $rids;
 }
@@ -455,33 +477,19 @@ function pift_cron_check_auto_followup(array $result) {
     $test = pift_test_get($result['test_id']);
     if ($test['fid']) {
       // Get the current issue state and ensure that the test is the last one
-      // for the particular issue. Cycle through clauses to remove the need for
-      // an OR clause and thus improve performance.
+      // for the particular issue.
       $results = array();
-      foreach (array('u.nid = i.nid', 'cu.nid = i.nid') as $clause) {
-        $result = db_query('SELECT t.test_id, t.id
-                            FROM {pift_test} t
-                            LEFT JOIN {upload} u
-                              ON (t.type = :type AND t.id = u.fid)
-                            LEFT JOIN {comment_upload} cu
-                              ON (t.type = :type AND t.id = cu.fid)
-                            JOIN {project_issues} i
-                              ON ' . $clause . '
-                            WHERE u.nid = :nid OR cu.nid = :nid
-                            ORDER BY t.id DESC
-                            LIMIT 1',
-                            array(
-                              ':type' => PIFT_TYPE_FILE,
-                              ':nid' => $test['nid'],
-                            ), array('fetch' => PDO::FETCH_ASSOC));
-        $results[] = $result;
-      }
-
-      // To simulate OR clause and descending order by 'id' select the test_id
-      // that has the highest 'id' value.
-      $test_id = $results[0]['id'] > $results[1]['id'] ? $results[0]['test_id'] : $results[1]['test_id'];
-
-      if ($test_id == $test['test_id'] && pift_test_check_criteria_issue(node_load($test['nid']))) {
+      $query = db_select('pift_test', 't', array('fetch' => PDO::FETCH_ASSOC))
+        ->fields('t', array('test_id', 'id'))
+        ->condition('t.type', PIFT_TYPE_FILE, '=');
+      $query->leftJoin('field_data_field_issue_files', 'fd', 't.id = fd.field_issue_files_fid');
+      $query->join('project_issues', 'i', 'fd.entity_id = i.nid');
+      $query->condition('fd.entity_id', $test['nid'], '=');
+      $query->orderBy('t.id', 'DESC')
+        ->range(0,1);
+      $result = $query->execute()->fetchField();
+
+      if ($result == $test['test_id'] && pift_test_check_criteria_issue(node_load($test['nid']))) {
         // Test is last one for the particular issue and still fits the criteria.
         pift_cron_auto_followup($test['nid'], $test['cid'], $test['filename']);
       }
@@ -497,11 +505,11 @@ function pift_cron_check_auto_followup(array $result) {
  * @param string $filename Name of file.
  */
 function pift_cron_auto_followup($nid, $cid, $filename) {
-  project_issue_add_auto_followup(array(
-    'nid' => $nid,
-    'sid' => PIFT_FOLLOWUP_FAIL,
-    'comment' => theme('pift_auto_followup', array('type' => 'fail', 'nid' => $nid, 'cid' => $cid, 'filename' => $filename)),
-  ));
+  $node = node_load($nid);
+  $node->field_issue_status['value'] = PIFT_FOLLOWUP_FAIL;
+  $node->nodechanges_uid = variable_get('project_issue_followup_user', drupal_anonymous_user()->uid);
+  $node->nodechanges_comment_body['value'] = theme('pift_auto_followup', array('type' => 'fail', 'nid' => $nid, 'cid' => $cid, 'filename' => $filename));
+  node_save($node);
 }
 
 /**
