Index: /trunk/ippTools/src/regtool.c
===================================================================
--- /trunk/ippTools/src/regtool.c	(revision 8267)
+++ /trunk/ippTools/src/regtool.c	(revision 8268)
@@ -167,15 +167,23 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // make sure that the exp_id(s) are ready to be updated based on the same
-    // critera used in pendingexpMode
-    char *query =
-        "SELECT newImfile.* FROM newImfile"
-        " LEFT JOIN newExp USING(exp_id)"
-        " LEFT JOIN rawScienceExp USING(exp_id)"
-        " LEFT JOIN rawDetrendExp USING (exp_id)"
-        " WHERE newExp.exp_id is NOT NULL"
-        " AND rawScienceExp.exp_id IS NULL"
-        " AND rawDetrendExp.exp_id IS NULL";
-
+    // make sure that the exp_id(s) are ready to be updated based on:
+    // exp_id is not in rawScienceExp
+    // exp_id is not in rawDetrendExp
+    // exp_id is not in newImfile
+    // that the correct count of imfiles is in rawImfile
+    psString query = psStringCopy("SELECT newExp.* FROM newExp LEFT JOIN newImfile USING(exp_id) LEFT JOIN rawScienceExp USING(exp_id) LEFT JOIN rawDetrendExp USING(exp_id) WHERE newExp.exp_id IS NOT NULL AND newImfile.exp_id IS NULL AND rawScienceExp.exp_id IS NULL AND newExp.imfiles = (SELECT COUNT(exp_id) FROM rawImfile GROUP BY exp_id)");
+
+    {        
+        bool status = false;
+        psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id");
+            return false;
+        }
+        if (exp_id) {
+            psStringAppend(&query, " AND newExp.exp_id = '%s'", exp_id);
+        }
+    }
+    
     if (!p_psDBRunQuery(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -293,5 +301,4 @@
             newImfileRow *object = newImfileObjectFromMetadata(newImfiles->data[i]);
             rawImfileRow *imfile = newToRawImfile(config, object); 
-            psFree(object);
             if (!imfile) {
                 // rollback
@@ -300,4 +307,5 @@
                 }
                 psError(PS_ERR_UNKNOWN, false, "failed to create a new rawImfile row");
+                psFree(object);
                 psFree(newImfiles);
                 return false;
@@ -310,8 +318,20 @@
                 psError(PS_ERR_UNKNOWN, false, "failed to insert row into the database");
                 psFree(imfile);
+                psFree(object);
                 psFree(newImfiles);
                 return false;
             }
             psFree(imfile);
+            if (!newImfileDeleteObject(config->dbh, object)) {
+                // rollback
+                if (!psDBRollback(config->dbh)) {
+                    psError(PS_ERR_UNKNOWN, false, "database error");
+                }
+                psError(PS_ERR_UNKNOWN, false, "failed to delete row from the database");
+                psFree(object);
+                psFree(newImfiles);
+                return false;
+            }
+            psFree(object);
         }
 
Index: /trunk/ippTools/src/regtoolConfig.c
===================================================================
--- /trunk/ippTools/src/regtoolConfig.c	(revision 8267)
+++ /trunk/ippTools/src/regtoolConfig.c	(revision 8268)
@@ -113,5 +113,6 @@
     PXTOOL_MODE("-pendingexp",   P0SEARCH_MODE_PENDINGEXP,  pendingexpArgs);
     PXTOOL_MODE("-pendingimfile",P0SEARCH_MODE_PENDINGIMFILE,pendingimfileArgs);
-    PXTOOL_MODE("-updateimfile", P0SEARCH_MODE_UPDATEIMFILE, updateimfileArgs);
+    PXTOOL_MODE("-updateexp",    P0SEARCH_MODE_UPDATEEXP,   updateexpArgs);
+    PXTOOL_MODE("-updateimfile", P0SEARCH_MODE_UPDATEIMFILE,updateimfileArgs);
 
     bool argErr = false;
