Index: trunk/ippTools/src/magicdstool.c
===================================================================
--- trunk/ippTools/src/magicdstool.c	(revision 27785)
+++ trunk/ippTools/src/magicdstool.c	(revision 27786)
@@ -572,5 +572,4 @@
     // we can transition by query as well
 
-
     psMetadata *where = psMetadataAlloc();
     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
@@ -1225,11 +1224,4 @@
     }
 
-    psString stateCheck = NULL;
-    if (!strcmp(state, "goto_cleaned")) {
-        // science cleanup sets runs to goto_cleaned. Don't undo it if already cleaned
-        psStringAppend(&stateCheck, " AND magicDSRun.state != 'cleaned'");
-    }
-
-
     psString query = NULL;
     psStringAppend(&query, "UPDATE magicDSRun SET state = '%s' %s\n", state, extraSetStr ? extraSetStr : "");
@@ -1241,12 +1233,16 @@
         psFree(whereClause);
     } else {
-        psError(PS_ERR_UNKNOWN, true, "search arugments are required");
-        return false;
-    }
-
-    if (stateCheck) {
-        psStringAppend(&query, stateCheck);
-    }
-    psFree(stateCheck);
+        psError(PS_ERR_UNKNOWN, true, "search arguments are required");
+        return false;
+    }
+
+    if (!strcmp(state, "goto_cleaned")) {
+        // Don't set state back to goto_cleaned if it is already cleaned
+        psStringAppend(&query, " AND (magicDSRun.state != 'cleaned')");
+
+        // don't clean up magicDSRun's where stage is camera
+        psStringAppend(&query, " AND (magicDSRun.stage != 'camera')");
+    }
+
     if (!p_psDBRunQuery(config->dbh, query)) {
         psError(PS_ERR_UNKNOWN, false,
