diff --git a/pift.cron.inc b/pift.cron.inc
index f4e9477..3e7f372 100644
--- a/pift.cron.inc
+++ b/pift.cron.inc
@@ -183,30 +183,35 @@ function pift_cron_queue_batch_build() {
  */
 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
+  $result = db_query('SELECT f.fid, f.filepath, t.nid, cu.cid AS c_cid
                       FROM {pift_test} t
                       JOIN {files} f
                         ON (t.type = %d 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 = %d
                       LIMIT %d', PIFT_TYPE_FILE, PIFT_STATUS_QUEUE, PIFT_XMLRPC_MAX);
   while ($file = db_fetch_array($result)) {
     // 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'];
+    $issue_nid = $file['nid'];
     $item = array(
       'client_identifier' => $file['fid'],
       'file_url' => file_create_url($file['filepath']),
     );
 
-
+    // have pi.nid
+    // check if pi.rid is 0
+    // If not,
     $branch_info_result = db_fetch_array(db_query('SELECT prn.nid AS rid, prn.version_major, prn.tag
                              FROM {project_issues} pi, {project_release_nodes} prn
                              WHERE pi.nid = %d AND pi.rid = prn.nid', $issue_nid));
+    // if so,
+        // OH CRAP.  No versions on sandbox issue queues.
+
 
-    $item['branch_identifier'] = $branch_info_result['rid'];
+    if (!empty($branch_info_result)) {
+      $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.
 
@@ -498,3 +503,30 @@ function pift_cron_response_code($response_code) {
       return 'Unknown';
   }
 }
+
+/**
+ * Attempt to parse a branch/tag string from a given filename.
+ *
+ * This function will look at the end of a filename for two underscores
+ * followed by some additional text.  If found, it will check the
+ * versioncontrol_labels table for a branch/tag name which matches that text,
+ * and  return the release_nid (or, if no releases, the versioncontrol_labels
+ * label_id) associated with that branch/tag and project combination.  If
+ * the pattern does not match, or a associated branch/tag name can not be
+ * found, it returns FALSE.
+ *
+ * @param string $filename File name to parse
+ * @param integer $repo_id VCS repository identifier
+ *
+ * @return integer Representation of release nid, VCS label_id, or FALSE
+ */
+function pift_cron_parse_branch_from_filename($filename, $repo_id) {
+  // $regex = '/__[0-9]+.([0-9]+|x)([-|_][0-9]+.([0-9]+|x))?([-|_](dev|alpha((\d)+)?|beta((\d)+)?|rc((\d)+)?))?.patch$/';
+  $regex = '/__[a-zA-Z0-9_\-.]+.patch$/';
+  if (!empty(preg_match($regex, $filename, $branchname))) {
+    // Perform database lookup on parsed label
+
+
+  }
+
+}
diff --git a/pift.install b/pift.install
index 330ff1b..02e92ac 100644
--- a/pift.install
+++ b/pift.install
@@ -27,11 +27,17 @@ function pift_schema() {
         'not null' => TRUE,
       ),
       'id' => array(
-        'description' => t('Related test detail record ID, either rid, or fid.'),
+        'description' => t('Related test detail record ID, either label_id, or fid.'),
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
       ),
+      'nid' => array(
+        'description' => t('Related test nid information, either rid, or pi.nid.'),
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+      ),
       'status' => array(
         'description' => t('Status of the test, PIFT_STATUS_*.'),
         'type' => 'int',
@@ -315,4 +321,28 @@ function pift_update_6206() {
   );
   db_change_field($ret, 'pift_test', 'message', 'message', $newattr);
   return $ret;
-}
\ No newline at end of file
+}
+
+/**
+ * Change schema to add pift_test.nid column, and update branch test unique id
+ */
+function pift_update_6207() {
+  // TODO:  Is this punishing enough that it should be converted to use Batch API?
+  $ret = array();
+  $newattr = array(
+    'description' => t('Related test nid information, either rid, or pi.nid.'),
+    'type' => 'int',
+    'unsigned' => TRUE,
+    'not null' => FALSE,
+  );
+  // Add nid column to pift_test
+  db_add_field($ret, 'pift_test', 'nid', $newattr);
+  // Datafill nid for branch tests
+  $ret[] = update_sql("UPDATE {pift_test} SET nid = id WHERE type = 1");
+  // Datafill nid for file tests
+  $ret[] = update_sql("UPDATE {pift_test} pt, {upload} u SET pt.nid = u.nid WHERE pt.id = u.fid AND pt.type = 2");
+  $ret[] = update_sql("UPDATE {pift_test} pt, {comment_upload} cu SET pt.nid = cu.nid WHERE pt.id = cu.fid AND pt.type = 2");
+  // Update id column for branch tests
+  $ret[] = update_sql("UPDATE {pift_test} pt, {versioncontrol_release_labels} vcs SET pt.id = vcs.label_id WHERE pt.id = vcs.release_nid and pt_type = 1");
+  return $ret;
+}
