Index: /trunk/ippScripts/scripts/addstar_run.pl
===================================================================
--- /trunk/ippScripts/scripts/addstar_run.pl	(revision 38936)
+++ /trunk/ippScripts/scripts/addstar_run.pl	(revision 38937)
@@ -31,6 +31,11 @@
 my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1);
 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
+my $fftool  = can_run('fftool') or (warn "Can't find fftool" and $missing_tools = 1);
+
 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
+
 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
+my $loadgalphot = can_run('loadgalphot') or (warn "Can't find loadgalphot" and $missing_tools = 1);
+
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -92,4 +97,15 @@
 }
 
+my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
+
+# Output products
+$ipprc->outroot_prepare($outroot);
+
+
+#
+# Step 1: sort out reductions / recipes
+#
+
+
 # Recipes to use based on reduction class
 $reduction = 'DEFAULT' unless defined $reduction;
@@ -101,9 +117,12 @@
 #} 
 
-if ($stage =~/fullforce/) {
+if ($stage eq 'fullforce') {
     $reduction='DEFAULT';
     #hardwired because why not
 }
-if ($stage =~/diff/) {
+elsif ($stage eq 'fullforce_summary') {
+    $reduction = 'DEFAULT';
+}
+elsif ($stage eq 'diff') {
     $reduction='DEFAULT';
     #hardwired because why not
@@ -112,16 +131,16 @@
 my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR');
 # XXX This is now not used: do we still need it?
-if ($stage =~/cam/) {
+if ($stage eq 'cam') {
   $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
 }
-if ($stage =~/stack/) {
+elsif ($stage eq 'stack') {
   $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STACK'); # Recipe to use
+}
+elsif ($stage eq 'skycal') {
+    $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use                                                              
 }
 #if ($stage =~/staticsky/) {
 #  $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR_STATICSKY'); # Recipe to use
 #}
-if ($stage =~/skycal/) {
-    $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use                                                              
-}
 
 
@@ -129,10 +148,11 @@
 &my_die("Unrecognised ADDSTAR recipe", $add_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_addstar;
 
-my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
-
-# Output products
-$ipprc->outroot_prepare($outroot);
 
 # the camera configurations should define the psastro output to be a single file (MEF), regardless of the inputs
+
+#
+# Step 2: Determine where sources should come from, modify them as needed.
+#
+
 
 # it was PSASTRO.OUTPUT
@@ -141,18 +161,16 @@
 my $fpaObjectsAlt = $fpaObjects;
 
-if ($stage =~ /skycal/) {
+if ($stage eq 'skycal') {
     #should be ok for skycal?
     print "using $fpaObjects for $stage\n";
 }
-if ($stage =~/diff/) {
+elsif ($stage eq 'diff') {
     print "using $fpaObjects for $stage\n";
 }
-if ($stage =~/fullforce/)  {
+elsif ($stage eq 'fullforce')  {
     print "using $fpaObjects for $stage\n";
 } 
 
-
-
-if ($stage =~ /cam/) {
+if ($stage eq 'cam') {
     # if it is cam stage we need to be careful when grabbing the filename. 
     # This breaks down into a few steps: 
@@ -197,8 +215,11 @@
 }
 
-if (($stage =~/stack/ || $stage =~ /skycal/ || $stage =~/diff/ || $stage=~/fullforce/)) {
+if (($stage eq 'stack') || 
+    ($stage eq 'skycal') || 
+    ($stage eq 'diff') || 
+    ($stage eq 'fullforce')||
+    ($stage eq 'fullforce_summary')) {
     $fpaObjects =~ s/smf$/cmf/;
     $fpaObjectsAlt =~ s/smf$/cmf/;
-
 }
 
@@ -206,5 +227,5 @@
 my $fpaObjects2;
 my $checkalt = 0;
-if ($stage =~/staticsky/) {
+if ($stage eq 'staticsky') {
     $checkalt = 1;
     my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $stageroot); #this is mostly rigtht except the .cmf needs either
@@ -239,7 +260,10 @@
 	$fpaObjects = $fpaObjects1;
     }
-     
-
-}
+}
+
+
+#
+# Step 3 Set up addtool/loadgalphot commands.
+#
 
 my $traceDest  = $ipprc->filename("TRACE.EXP",          $outroot) or &my_die("Missing entry from camera config", $add_id, $PS_EXIT_CONFIG_ERROR);
@@ -251,8 +275,9 @@
     $dvodbReal = $ipprc->convert_filename_absolute( $dvodbReal ) or &my_die("can't get path for dvodb", $add_id, $PS_EXIT_CONFIG_ERROR);
 }
+
 my $dtime_addstar = 0;
 if (defined $dvodbReal) {
     if ($minidvodb) {
-	my $command = "addtool -listminidvodbrun ";
+	my $command = "$addtool -listminidvodbrun ";
 	$command .= " -minidvodb_group $minidvodb_group" if defined $minidvodb_group;
 	$command .= " -minidvodb_name $minidvodb_name" if defined $minidvodb_name;
@@ -285,5 +310,4 @@
     unless ($no_op) {
             print $dvodbReal;
-	    
 	    ## addstar can either save the full set of detections, or just
 	    ## the image metadata, in the dvodb.  this is set in the
@@ -311,27 +335,62 @@
 	    }		
 
-	    # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
-	    my $command  = "$addstar -update"; # XXX optionally set -update?
-	    $command .= " -D CAMERA $camdir";
-	    $command .= " -D CATDIR $minidvodb_path";
-	    $command .= " -D ZERO_POINT_OPTION $zeroPointOption";
-	    $command .= " $realFile";
-	    $command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference
-	    $command .= " -image" if $image_only;
-	    if ($stage =~ /staticsky/) {
-		$command .= " -accept-astrom -quick-airmass";
-	    }  #careful here - this matches staticsky and staticsky_multi
-	    if ($stage =~ /skycal/) {
-		$command .= " -quick-airmass";
-	    }  #careful here - this matches staticsky and staticsky_multi
-	    if ($stage =~ /diff/) {
-		$command .= " -accept-astrom";
+	    my $command;
+
+	    if ($stage ne 'fullforce_summary') {
+		# require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
+		$command  = "$addstar -update"; # XXX optionally set -update?
+		$command .= " -D CAMERA $camdir";
+		$command .= " -D CATDIR $minidvodb_path";
+		$command .= " -D ZERO_POINT_OPTION $zeroPointOption";
+		$command .= " $realFile";
+		$command .= " -use-name $fpaObjects"; # DVO wants the neb-name as a file reference
+		$command .= " -image" if $image_only;
+		if ($stage =~ /staticsky/) {
+		    $command .= " -accept-astrom -quick-airmass";
+		}  #careful here - this matches staticsky and staticsky_multi
+		if ($stage =~ /skycal/) {
+		    $command .= " -quick-airmass";
+		}  #careful here - this matches staticsky and staticsky_multi
+		if ($stage =~ /diff/) {
+		    $command .= " -accept-astrom";
+		}
+		if ($stage =~ /fullforce/) {
+		    $command .= " -accept-astrom -xrad"; 
+		}
 	    }
-	    if ($stage =~ /fullforce/) {
-		$command .= " -accept-astrom -xrad"; 
+	    else { # Full force summary case
+		# We need to know the filter to set up the photcode, as the summaries do not include that in the header.
+		# We /could/ set up the addtool stuff to pass that in to the script when needed, but that would require adding 
+		# a lot of extra hooks and option handlers.  Therefore, call out to fftool, and get the filter that way, and
+		# construct the correct photcode.
+
+		my $photcode = '';
+		{
+		    my $ff_command = "$fftool -dbname ${dbname} -summary -ff_id ${stage_id}";
+		    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+			run(command => $command, verbose => $verbose);
+		    unless ($success) {
+			$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+			&my_die("Unable to fetch filter via fftool: $error_code", $add_id, $error_code);
+		    }
+		    my $MDlist = $mdcParser->parse(join "", @$stdout_buf) or
+			&my_die("Unable to determine ff summary information.", $add_id, $error_code);
+		    my $metadata = parse_md_list($MDlist);
+		    my $ffSummary = $metadata->[0];
+		    my $filter = $ffSummary->{filter};
+		    
+		    $filter =~ s/\.00000//;
+		    $photcode = "GPC1.${filter}.ForcedWarp";
+		}
+
+		$command =  "$loadgalphot -v ";
+		$command .= " -D CAMERA $camdir ";
+		$command .= " -D CATDIR $minidvodb_path ";
+		$command .= " $realFile ";
+		$command .= " -p $photcode ";
 	    }
-
+		    
 	    my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
-
+	    
 	    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
 		run(command => $command, verbose => $verbose);
Index: /trunk/ippTasks/addstar.pro
===================================================================
--- /trunk/ippTasks/addstar.pro	(revision 38936)
+++ /trunk/ippTasks/addstar.pro	(revision 38937)
@@ -244,5 +244,7 @@
 $addstar_revert_DB_SC = 0 
 $addstar_revert_DB_FF = 0 
+$addstar_revert_DB_FFS = 0
 $addstar_revert_DB_DF = 0 
+
 
 #$LOADEXEC_ADD = 300
@@ -452,4 +454,7 @@
         sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
     end
+    if ("$STAGE" == "fullforce_summary")
+	sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
 
   
@@ -468,12 +473,16 @@
       $run = $run --stage_id $STAGE_ID
     end
-   if ("$STAGE" == "skycal")
+    if ("$STAGE" == "skycal")
       $run = $run --stage_id $STAGE_ID
     end
-   if ("$STAGE" == "diff")
+    if ("$STAGE" == "diff")
       $run = $run --stage_id $STAGE_ID --stage_extra1 $STAGE_EXTRA1
     end
-   if ("$STAGE" == "fullforce")
+    if ("$STAGE" == "fullforce")
       $run = $run --stage_id $STAGE_ID --stage_extra1 $STAGE_EXTRA1
+    end
+    if ("$STAGE" == "fullforce_summary")
+    # This shouldn't need a stage_extra1, as there are no subcomponents to the ff summary.
+      $run = $run --stage_id
     end
 
@@ -596,4 +605,7 @@
         sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
     end
+    if ("$STAGE" == "fullforce_summary")
+	sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
 
   
@@ -949,2 +961,49 @@
   end
 end
+
+task addstar.revert.fullforce_summary
+  host         local
+
+  periods      -poll 5.0
+  periods      -exec 60.0
+  periods      -timeout 1200
+  npending     1
+  active        false
+
+  stdout NULL
+  stderr $LOGDIR/revert.log
+
+  task.exec
+    if ($LABEL:n == 0) break
+    $run = addtool -revertprocessedexp -stage fullforce_summary
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks                                                                   
+      option $DB:$addstar_revert_DB_FFS
+      $run = $run -dbname $DB:$addstar_revert_DB_FFS
+      $addstar_revert_DB_FFS ++
+      if ($addstar_revert_DB_FFS >= $DB:n) set addstar_revert_DB_FFS = 0
+    end
+     add_poll_labels run
+    command $run
+  end
+
+  # success                                                                                                   
+  task.exit    0
+  end
+
+  # locked list                                                                                               
+  task.exit    default
+    showcommand failure
+  end
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?                                                                                      
+  task.exit    timeout
+    showcommand timeout
+  end
+end
Index: /trunk/ippTools/share/addtool_find_ffsummary_id.sql
===================================================================
--- /trunk/ippTools/share/addtool_find_ffsummary_id.sql	(revision 38936)
+++ /trunk/ippTools/share/addtool_find_ffsummary_id.sql	(revision 38937)
@@ -1,15 +1,12 @@
-SELECT
-     fullForceRun.*
-FROM 
-     fullForceRun
-JOIN fullForceSummary using (ff_id)
-
-LEFT JOIN (SELECT ff_id       AS added_ff_id,
-                  addRun.dvodb AS previous_dvodb
-           FROM addRun
-JOIN fullForceRun on (ff_id = stage_id and addRun.stage = 'fullforce_summary')
-          ) as foo
-     ON ff_id = added_ff_id 
-     --AND stage = 'skycal'
+SELECT fullForceRun.* FROM fullForceRun
+JOIN fullForceSummary USING (ff_id)
+LEFT JOIN (
+     SELECT ff_id AS added_ff_id,
+            addRun.dvodb AS previous_dvodb
+     FROM addRun
+     JOIN fullForceRun ON (ff_id = stage_id and addRun.stage = 'fullforce_summary')
+     ) as foo
+ON ff_id = added_ff_id 
+     -- AND stage = 'skycal'
      -- hook for qualifying the join on the previous_dvodb
      AND %s
Index: /trunk/ippTools/share/addtool_find_ffsummary_id_dvo.sql
===================================================================
--- /trunk/ippTools/share/addtool_find_ffsummary_id_dvo.sql	(revision 38936)
+++ /trunk/ippTools/share/addtool_find_ffsummary_id_dvo.sql	(revision 38937)
@@ -1,10 +1,15 @@
-SELECT fullForceRun.* FROM fullForceRun JOIN fullForceSummary using (ff_id)
-JOIN skycalRun using (skycal_id) join stackRun using (stack_id) 
-JOIN skycell using (skycell_id, tess_id)
+SELECT fullForceRun.* FROM fullForceRun 
+JOIN fullForceSummary USING (ff_id)
+JOIN skycalRun USING (skycal_id) 
+JOIN stackRun USING (stack_id) 
+JOIN skycell USING (skycell_id, tess_id)
 
-WHERE fullForceRun.state = 'full' and fullForceSummary.quality = 0 and fullForceSummary.fault = 0 
-    AND fullForceRun.ff_id NOT IN (SELECT fullForceRun.ff_id
-       FROM addRun
-       JOIN fullForceRun on (fullForceRun.ff_id = addRun.stage_id and addRun.stage = 'fullforce_summary') JOIN fullForceSummary on (fullForceRun.ff_id = fullForceSummary.ff_id)
+WHERE fullForceRun.state = 'full' 
+AND fullForceSummary.quality = 0 
+AND fullForceSummary.fault = 0 
+AND fullForceRun.ff_id NOT IN (
+    SELECT fullForceRun.ff_id FROM addRun
+    JOIN fullForceRun ON (fullForceRun.ff_id = addRun.stage_id and addRun.stage = 'fullforce_summary') 
+    JOIN fullForceSummary ON (fullForceRun.ff_id = fullForceSummary.ff_id)
        WHERE addRun.stage = 'fullforce_summary' AND %s
-      )
+    )
Index: /trunk/ippTools/src/addtool.c
===================================================================
--- /trunk/ippTools/src/addtool.c	(revision 38936)
+++ /trunk/ippTools/src/addtool.c	(revision 38937)
@@ -124,54 +124,5 @@
     PXOPT_COPY_S64(config->args, where,  "-diff_id",  "diffRun.diff_id", "==");
     PXOPT_COPY_S64(config->args, where,  "-ff_id",  "fullForceRun.ff_id", "==");
-
-    PXOPT_LOOKUP_STR(stage,       config->args, "-stage", false, false);
-    if (strcmp(stage, "cam")== 0) {
-      pxcamGetSearchArgs (config, where);
-      pxAddLabelSearchArgs (config, where, "-label",     "camRun.label", "=="); // define using camRun label
-      pxAddLabelSearchArgs (config, where, "-data_group","camRun.data_group", "=="); // define using camRun label
-      PXOPT_COPY_STR(config->args, where,  "-reduction", "camRun.reduction", "==");
-    }
-    if (strcmp(stage, "stack")== 0) {
-      pxAddLabelSearchArgs (config, where, "-label",     "stackRun.label", "=="); // define using camRun label
-      pxAddLabelSearchArgs (config, where, "-data_group","stackRun.data_group", "=="); // define using camRun label
-      PXOPT_COPY_STR(config->args, where,  "-reduction", "stackRun.reduction", "==");
-      pxAddLabelSearchArgs (config, where, "-filter",     "stackRun.filter", "=="); // define using camRun label
-    }
-    if (strcmp(stage, "staticsky")== 0) {
-      pxAddLabelSearchArgs (config, where, "-label",     "staticskyRun.label", "=="); // define using camRun label
-      pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label
-      PXOPT_COPY_STR(config->args, where,  "-reduction", "staticskyRun.reduction", "==");
-    //no filter here
-    }
-    if (strcmp(stage, "skycal")==0) {
-      pxAddLabelSearchArgs (config, where, "-label",     "skycalRun.label", "=="); //define using skycalRun label
-      pxAddLabelSearchArgs (config, where, "-data_group","skycalRun.data_group", "==");
-      PXOPT_COPY_STR(config->args, where,  "-reduction", "skycalRun.reduction",  "==");
-    }
-    if (strcmp(stage, "diff")==0) {
-      pxAddLabelSearchArgs (config, where, "-label",     "diffRun.label", "=="); //define using skycalRun label
-      pxAddLabelSearchArgs (config, where, "-data_group","diffRun.data_group", "==");
-      PXOPT_COPY_STR(config->args, where,  "-reduction", "diffRun.reduction",  "==");
-    }
-    if (strcmp(stage, "fullforce")==0) {
-      pxAddLabelSearchArgs (config, where, "-label",     "fullForceRun.label", "=="); //define using skycalRun label
-      pxAddLabelSearchArgs (config, where, "-data_group","fullForceRun.data_group", "==");
-      PXOPT_COPY_STR(config->args, where,  "-reduction", "fullForceRun.reduction",  "==");
-    }
-    if (strcmp(stage, "fullforce_summary")==0) {
-      //should be nearly identical to fullforce (uses the same tables)
-      pxAddLabelSearchArgs (config, where, "-label",     "fullForceRun.label", "=="); 
-      pxAddLabelSearchArgs (config, where, "-data_group","fullForceRun.data_group", "==");
-      PXOPT_COPY_STR(config->args, where,  "-reduction", "fullForceRun.reduction",  "==");
-    }
-
- 
- 
-    if (!psListLength(where->list)) {
-        psFree(where);
-        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
-        return false;
-    }
-    
+        
     // PXOPT_LOOKUP_STR(stage,       config->args, "-stage", false, false);
     PXOPT_LOOKUP_STR(workdir,     config->args, "-set_workdir", false, false);
@@ -194,63 +145,119 @@
     PXOPT_LOOKUP_F32(mindec,     config->args, "-set_mindec", false, false);
     PXOPT_LOOKUP_F32(maxdec,     config->args, "-set_maxdec", false, false);
+
+    // Handle stages
+    PXOPT_LOOKUP_STR(stage,       config->args, "-stage", false, false);
+    if (strcmp(stage, "cam") == 0) {
+      pxcamGetSearchArgs (config, where);
+      pxAddLabelSearchArgs (config, where, "-label",     "camRun.label", "=="); // define using camRun label
+      pxAddLabelSearchArgs (config, where, "-data_group","camRun.data_group", "=="); // define using camRun label
+      PXOPT_COPY_STR(config->args, where,  "-reduction", "camRun.reduction", "==");
+    }
+    else if (strcmp(stage, "stack") == 0) {
+      pxAddLabelSearchArgs (config, where, "-label",     "stackRun.label", "=="); // define using camRun label
+      pxAddLabelSearchArgs (config, where, "-data_group","stackRun.data_group", "=="); // define using camRun label
+      PXOPT_COPY_STR(config->args, where,  "-reduction", "stackRun.reduction", "==");
+      pxAddLabelSearchArgs (config, where, "-filter",     "stackRun.filter", "=="); // define using camRun label
+    }
+    else if (strcmp(stage, "staticsky") == 0) {
+      pxAddLabelSearchArgs (config, where, "-label",     "staticskyRun.label", "=="); // define using camRun label
+      pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label
+      PXOPT_COPY_STR(config->args, where,  "-reduction", "staticskyRun.reduction", "==");
+      //no filter here
+    }
+    else if (strcmp(stage, "skycal") == 0) {
+      pxAddLabelSearchArgs (config, where, "-label",     "skycalRun.label", "=="); //define using skycalRun label
+      pxAddLabelSearchArgs (config, where, "-data_group","skycalRun.data_group", "==");
+      PXOPT_COPY_STR(config->args, where,  "-reduction", "skycalRun.reduction",  "==");
+    }
+    else if (strcmp(stage, "diff") == 0) {
+      pxAddLabelSearchArgs (config, where, "-label",     "diffRun.label", "=="); //define using diffRun label
+      pxAddLabelSearchArgs (config, where, "-data_group","diffRun.data_group", "==");
+      PXOPT_COPY_STR(config->args, where,  "-reduction", "diffRun.reduction",  "==");
+    }
+    else if (strcmp(stage, "fullforce") == 0) {
+      pxAddLabelSearchArgs (config, where, "-label",     "fullForceRun.label", "=="); //define using fullForceRun label
+      pxAddLabelSearchArgs (config, where, "-data_group","fullForceRun.data_group", "==");
+      PXOPT_COPY_STR(config->args, where,  "-reduction", "fullForceRun.reduction",  "==");
+    }
+    else if (strcmp(stage, "fullforce_summary")==0) {
+      //should be nearly identical to fullforce (uses the same tables)
+      pxAddLabelSearchArgs (config, where, "-label",     "fullForceRun.label", "=="); 
+      pxAddLabelSearchArgs (config, where, "-data_group","fullForceRun.data_group", "==");
+      PXOPT_COPY_STR(config->args, where,  "-reduction", "fullForceRun.reduction",  "==");
+    }
+ 
+    if (!psListLength(where->list)) {
+        psFree(where);
+        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
+        return false;
+    }
    
+    // Select either destreaked or uncensored data.  CZW: Should this be defaulted to uncensored?
+    if (!(destreaked && uncensored) && (destreaked || uncensored)) {
+      //if one of destreaked and uncensored is true, but not both
+      if (destreaked) {
+	psTrace("addtool.c", PS_LOG_INFO, "using -destreaked\n");
+      } else {
+	psTrace("addtool.c", PS_LOG_INFO, "using -unscensored\n");
+      }
+    } else {
+      if (destreaked && uncensored) {
+	psError(PS_ERR_UNKNOWN, false, "Both -destreaked and -uncensored are selected. Please use one or the other, not both, \n");
+	return false;
+      }
+      if (!destreaked && !uncensored) {
+	psError(PS_ERR_UNKNOWN, false, "Neither -destreaked or -uncensored are selected. Please use one.\n");
+	return false;
+      }
+    }
+    if ((strcmp(stage,"diff") == 0) ||
+	(strcmp(stage,"fullforce") == 0) ||
+	(strcmp(stage,"fullforce_summary") == 0)) {
+      if (! (dvodb)) {
+	psError(PS_ERR_UNKNOWN, false, "The SQL is not correctly written to handle this case (-set_dvodb not specified), so stopping here.");
+	return(false);
+      }
+    }
+    
+    
     // prevent queueing an addRun if a given exposure has already been added to
     // the given dvo database
     psString dvodb_string = NULL;
     psString bare_query = NULL;
-
-    if (!(destreaked && uncensored) && (destreaked || uncensored)) {
-      //if one of destreaked and uncensored is true, but not both
-      if (destreaked) {
-      psTrace("addtool.c", PS_LOG_INFO, "using -destreaked\n");
-      } else {
-      psTrace("addtool.c", PS_LOG_INFO, "using -unscensored\n");
-      }
-    } else {
-      if (destreaked && uncensored) {
-	psError(PS_ERR_UNKNOWN, false, "Both -destreaked and -uncensored are selected. Please use one or the other, not both, \n");
-	return false;
-      }
-      if (!destreaked && !uncensored) {
-	psError(PS_ERR_UNKNOWN, false, "Neither -destreaked or -uncensored are selected. Please use one.\n");
-	 return false;
-      }
-    }
-
-    
-
-
+    
     if (strcmp(stage,"cam") == 0 ) {
-    if (dvodb) {
-      psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_cam_id_dvo.sql\n%s\n", dvodb,stage);
+      if (dvodb) {
+	psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_cam_id_dvo.sql\n%s\n", dvodb,stage);
         // find the cam_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_cam_id_dvo.sql");
 	// user supplied dvodb
 	psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
-    } else {
-      psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_cam_id.sql\n%s\n",stage);
+      } else {
+	psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_cam_id.sql\n%s\n",stage);
         // find the cam_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_cam_id.sql");
         // inherit dvodb from camRun, avoid matching NULL
         psStringAppend(&dvodb_string, "(camRun.dvodb IS NOT NULL AND previous_dvodb = camRun.dvodb)");
-    }
-    }
-    if (strcmp(stage,"stack") == 0) {
-    if (dvodb ) {
-      psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_stack_id_dvo.sql\n%s\n", dvodb,stage);
+      }
+    }
+
+    else if (strcmp(stage,"stack") == 0) {
+      if (dvodb) {
+	psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_stack_id_dvo.sql\n%s\n", dvodb,stage);
         // find the cam_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_stack_id_dvo.sql");
 	// user supplied dvodb
 	psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
-    } else {
-      psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_stack_id.sql\n%s\n",stage);
+      } else {
+	psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_stack_id.sql\n%s\n",stage);
         // find the cam_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_stack_id.sql");
         // inherit dvodb from camRun, avoid matching NULL
         psStringAppend(&dvodb_string, "(stackRun.dvodb IS NOT NULL AND previous_dvodb = stackRun.dvodb)");
-    }
-    }
-  
-    if (strcmp(stage,"staticsky") == 0) {
+      }
+    }
+
+    else if (strcmp(stage,"staticsky") == 0) {
       if (dvodb ) {
 	psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_sky_id_multi_dvo.sql\n%s\n", dvodb,stage);
@@ -267,17 +274,17 @@
       }
     }
-    
-    if (strcmp(stage,"skycal") == 0) {
-      if (dvodb ) {
+
+    else if (strcmp(stage,"skycal") == 0) {
+      if (dvodb) {
         psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_skycal_id_dvo.sql\n%s\n", dvodb,stage);
-        // find the skycal_id of all the exposures that we want to queue up.                                                                                                   
+        // find the skycal_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_skycal_id_dvo.sql");
-        // user supplied dvodb                                                                                                                                              
+        // user supplied dvodb
         psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
       } else {
         psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_skycal_id.sql\n%s\n",stage);
-        // find the skycal_id of all the exposures that we want to queue up.                                                                                                   
+        // find the skycal_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_skycal_id.sql");
-        // inherit dvodb from skycalRun, avoid matching NULL                                                                                                                   
+        // inherit dvodb from skycalRun, avoid matching NULL
         psStringAppend(&dvodb_string, "(skycalRun.dvodb IS NOT NULL AND previous_dvodb = skycalRun.dvodb)");
 	// this is silly, there is no dvodb in skycalRun...?
@@ -285,61 +292,54 @@
     }
 
-    if (strcmp(stage,"diff") == 0) {
-      if (dvodb ) {
+    else if (strcmp(stage,"diff") == 0) {
+      if (dvodb) {
         psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_diff_id_dvo.sql\n%s\n", dvodb,stage);
-        // find the skycal_id of all the exposures that we want to queue up.                                                                                                   
+        // find the skycal_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_diff_id_dvo.sql");
-        // user supplied dvodb                                                                                                                                              
+        // user supplied dvodb
         psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
       } else {
         psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_diff_id.sql\n%s\n",stage);
-        // find the skycal_id of all the exposures that we want to queue up.                                                                                                   
+        // find the skycal_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_diff_id.sql");
-        // inherit dvodb from skycalRun, avoid matching NULL                                                                                                                   
+        // inherit dvodb from skycalRun, avoid matching NULL
         psStringAppend(&dvodb_string, "(diffRun.dvodb IS NOT NULL AND previous_dvodb = diffRun.dvodb)");
 	// this is silly, there is no dvodb in skycalRun...?
       }
-      
-
-     }
-
-    if (strcmp(stage,"fullforce") == 0) {
-      if (dvodb ) {
+    }
+
+    else if (strcmp(stage,"fullforce") == 0) {
+      if (dvodb) {
         psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_ff_id_dvo.sql\n%s\n", dvodb,stage);
-        // find the skycal_id of all the exposures that we want to queue up.                                                                                                   
+        // find the skycal_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_ff_id_dvo.sql");
-        // user supplied dvodb                                                                                                                                              
+        // user supplied dvodb
         psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
       } else {
         psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_ff_id.sql\n%s\n",stage);
-        // find the skycal_id of all the exposures that we want to queue up.                                                                                                   
+        // find the skycal_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_ff_id.sql");
-        // inherit dvodb from skycalRun, avoid matching NULL                                                                                                                   
+        // inherit dvodb from skycalRun, avoid matching NULL
         psStringAppend(&dvodb_string, "(fullForceRun.dvodb IS NOT NULL AND previous_dvodb = fullForceRun.dvodb)");
 	// this is silly, there is no dvodb in skycalRun...?
       }
     }
-
-        if (strcmp(stage,"fullforce_summary") == 0) {
-      if (dvodb ) {
+    else if (strcmp(stage,"fullforce_summary") == 0) {
+      if (dvodb) {
         psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_ffsummary_id_dvo.sql\n%s\n", dvodb,stage);
-        // find the skycal_id of all the exposures that we want to queue up.                                                                                                   
+        // find the skycal_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_ffsummary_id_dvo.sql");
-        // user supplied dvodb                                                                                                                                              
+        // user supplied dvodb
         psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);
       } else {
         psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_ffsummary_id.sql\n%s\n",stage);
-        // find the skycal_id of all the exposures that we want to queue up.                                                                                                   
+        // find the skycal_id of all the exposures that we want to queue up.
         bare_query = pxDataGet("addtool_find_ffsummary_id.sql");
-        // inherit dvodb from skycalRun, avoid matching NULL                                                                                                                   
+        // inherit dvodb from skycalRun, avoid matching NULL
         psStringAppend(&dvodb_string, "(fullForceRun.dvodb IS NOT NULL AND previous_dvodb = fullForceRun.dvodb)");
 	// this is silly, there is no dvodb in skycalRun...?
       }
     }
-
-
-
-
-
+    
     if (!bare_query) {
         psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement");
@@ -347,4 +347,5 @@
 	return false;
     }
+    
     // Take the bare query and add the dvodb selector
     psString query = NULL;
@@ -357,27 +358,15 @@
         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
         psStringAppend(&query, " AND %s", whereClause);
-	if (strcmp(stage,"diff") == 0) {
+
+	if ((strcmp(stage,"diff") == 0)||
+	    (strcmp(stage,"fullforce") == 0)||
+	    (strcmp(stage,"fullforce_summary") == 0)) {
 	  //diff needs the ra /deg stuff
+	  //ff needs the ra /deg stuff
+	  //ff summary needs the ra /deg stuff
 	  psStringAppend(&query, " AND radeg >= %f", minra);
 	  psStringAppend(&query, " AND radeg <= %f", maxra);
 	  psStringAppend(&query, " AND decdeg >= %f", mindec);
 	  psStringAppend(&query, " AND decdeg <= %f", maxdec);
-
-	}
-	if (strcmp(stage,"fullforce") == 0) {
-	  //ff needs the ra /deg stuff
-	  psStringAppend(&query, " AND radeg >= %f", minra);
-	  psStringAppend(&query, " AND radeg <= %f", maxra);
-	  psStringAppend(&query, " AND decdeg >= %f", mindec);
-	  psStringAppend(&query, " AND decdeg <= %f", maxdec);
-
-	}
-	if (strcmp(stage,"fullforce_summary") == 0) {
-	  //ff needs the ra /deg stuff
-	  psStringAppend(&query, " AND radeg >= %f", minra);
-	  psStringAppend(&query, " AND radeg <= %f", maxra);
-	  psStringAppend(&query, " AND decdeg >= %f", mindec);
-	  psStringAppend(&query, " AND decdeg <= %f", maxdec);
-
 	}
 
@@ -391,9 +380,7 @@
     if (destreaked) {
       //This picks the magicked/censored ones
-      if (strcmp(stage,"cam") == 0) {
+      if ((strcmp(stage,"cam") == 0)||
+	  (strcmp(stage,"stack") == 0)) { 
         psStringAppend(&query, " AND (camRun.magicked > 0)");
-      }
-      if (strcmp(stage,"stack") == 0) {
-	psStringAppend(&query, " AND (stackRun.magicked > 0)");
       }
       // staticSky/skycal have no magicked column.
@@ -407,39 +394,32 @@
 	psStringAppend(&query, " AND (stackRun.magicked = 0)");
       }
-
-    }
-
-    //if we grab a group of camRun/stackRuns that have multiple camRun/stackRun pointing to the same exp_id/stack_id, and that exp_id/stack_id has never before been added to addRun, we need to group by exp_id/stack_id to ensure that only 1 of the camRun/stackRun for that exp_id is added to the addRun stage.
-
+    }
+
+    // if we grab a group of camRun/stackRuns that have multiple camRun/stackRun pointing to the same exp_id/stack_id, and that exp_id/stack_id has never before been added to addRun, we need to group by exp_id/stack_id to ensure that only 1 of the camRun/stackRun for that exp_id is added to the addRun stage.
+    
     if (strcmp(stage,"cam") == 0) {
-        psStringAppend(&query, " GROUP BY exp_id"); 
-   }
-      if (strcmp(stage,"stack") == 0) {
-	psStringAppend(&query, " GROUP BY stack_id");
-      }
-      //   if (strcmp(stage,"staticsky") == 0) {
-      //   psStringAppend(&query, " GROUP BY stack_id");
-      // }
-      if (strcmp(stage,"staticsky") == 0) {
-	psStringAppend(&query, " GROUP BY sky_id, stack_id");  //some reason it needs this
-      }
-      if (strcmp(stage,"skycal") == 0) {
-	psStringAppend(&query, " GROUP BY skycal_id, sky_id, stack_id ");  //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there
-      }
-      //needs to be checked HAF xxx
-      if (strcmp(stage,"diff") == 0) {
-
-	psStringAppend(&query, " GROUP BY diff_id, diff_skyfile_id ");  //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there
-      }
-      //needs to be checked HAF xxx
-      if (strcmp(stage,"fullforce") == 0) {
-	psStringAppend(&query, " GROUP BY ff_id, warp_id ");  //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there
-      }
-      if (strcmp(stage,"fullforce_summary") == 0) {
-	psStringAppend(&query, " GROUP BY ff_id ");  //needs to be checked, but should be fine: want 1 ff summary cmf.
-      }
-
-      psError(PS_ERR_UNKNOWN, false , query);
-
+      psStringAppend(&query, " GROUP BY exp_id"); 
+    }
+    else if (strcmp(stage,"stack") == 0) {
+      psStringAppend(&query, " GROUP BY stack_id");
+    }
+    else if (strcmp(stage,"staticsky") == 0) {
+      psStringAppend(&query, " GROUP BY sky_id, stack_id");  //some reason it needs this
+    }
+    else if (strcmp(stage,"skycal") == 0) {
+      psStringAppend(&query, " GROUP BY skycal_id, sky_id, stack_id ");  //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there
+    }
+    //needs to be checked HAF xxx
+    else if (strcmp(stage,"diff") == 0) {
+      psStringAppend(&query, " GROUP BY diff_id, diff_skyfile_id ");  //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there
+    }
+    //needs to be checked HAF xxx
+    else if (strcmp(stage,"fullforce") == 0) {
+      psStringAppend(&query, " GROUP BY ff_id, warp_id ");  //this needs checking, but I think it shoul be fine? it groups by lots of stuff (including stack - we only want one of each stack in there
+    }
+    else if (strcmp(stage,"fullforce_summary") == 0) {
+      psStringAppend(&query, " GROUP BY ff_id ");  //needs to be checked, but should be fine: want 1 ff summary cmf.
+    }
+    psError(PS_ERR_UNKNOWN, false , query);
 
     psTrace("addtool.c", PS_LOG_INFO,"query: \n\n%s\n\n",query);
@@ -447,89 +427,86 @@
     if (!p_psDBRunQuery(config->dbh, query)) {
       psError(PS_ERR_UNKNOWN, false, "database error, \n%s\n", query);
-        psFree(query);
-        return false;
+      psFree(query);
+      return false;
     }
     psFree(query);
-
+    
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      return false;
     }
     if (!psArrayLength(output)) {
-        psTrace("addtool", PS_LOG_INFO, "no rows found");
-        psFree(output);
-        return true;
-    }
-
+      psTrace("addtool", PS_LOG_INFO, "no rows found");
+      psFree(output);
+      return true;
+    }
+    
     if (pretend) {
-        // negative simple so the default is true
-        if (!ippdbPrintMetadatas(stdout, output, "addRun", !simple)) {
-            psError(PS_ERR_UNKNOWN, false, "failed to print array");
-            psFree(output);
-            return false;
-        }
-        psFree(output);
-        return true;
-    }
-
+      // negative simple so the default is true
+      if (!ippdbPrintMetadatas(stdout, output, "addRun", !simple)) {
+	psError(PS_ERR_UNKNOWN, false, "failed to print array");
+	psFree(output);
+	return false;
+      }
+      psFree(output);
+      return true;
+    }
+    
     // loop over our list of camRun rows to check the supplied and selected dvodb and workdir values:
     if (strcmp(stage,"cam") == 0) {
-    for (long i = 0; i < psArrayLength(output); i++) {
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
-
+	
 	camRunRow *row = camRunObjectFromMetadata(md);
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
+	  psFree(output);
+	  return false;
+        }
+	
         if (!dvodb && !row->dvodb) {
-            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, cam_id %" PRId64, row->label, row->cam_id);
-            psFree(output);
-            return false;
+	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, cam_id %" PRId64, row->label, row->cam_id);
+	  psFree(output);
+	  return false;
         }
         if (!workdir && !row->workdir) {
-            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, cam_id %" PRId64, row->label, row->cam_id);
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, cam_id %" PRId64, row->label, row->cam_id);
+	  psFree(output);
+	  return false;
+        }
+	
         psFree(row);
-    }
-    }
-    if (strcmp(stage,"stack") == 0) {
-    for (long i = 0; i < psArrayLength(output); i++) {
+      }
+    }
+    else if (strcmp(stage,"stack") == 0) {
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
-
+	
 	stackRunRow *row = stackRunObjectFromMetadata(md);
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
+	  psFree(output);
+	  return false;
+        }
+	
         if (!dvodb && !row->dvodb) {
-            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, stack_id %" PRId64, row->label, row->stack_id);
-            psFree(output);
-            return false;
+	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, stack_id %" PRId64, row->label, row->stack_id);
+	  psFree(output);
+	  return false;
         }
         if (!workdir && !row->workdir) {
-            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, stack_id %" PRId64, row->label, row->stack_id);
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, stack_id %" PRId64, row->label, row->stack_id);
+	  psFree(output);
+	  return false;
+        }
+	
         psFree(row);
-    }
-    }
-   
-
-
-    if (strcmp(stage,"staticsky") == 0) {
-    for (long i = 0; i < psArrayLength(output); i++) {
+      }
+    }
+    else if (strcmp(stage,"staticsky") == 0) {
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 	bool status = false;
@@ -543,32 +520,31 @@
 	  return false;
 	}
-
+	
 	staticskyRunRow *row = staticskyRunObjectFromMetadata(md);
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
+	  psFree(output);
+	  return false;
+        }
+	
         if (!dvodb) {  //there's no staticsky.dvodb
-            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, sky_id %" PRId64, row->label, row->sky_id);
-            psFree(output);
-            return false;
+	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, sky_id %" PRId64, row->label, row->sky_id);
+	  psFree(output);
+	  return false;
         }
         if (!workdir && !row->workdir) {
-            psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, sky_id %" PRId64, row->label, row->sky_id);
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, sky_id %" PRId64, row->label, row->sky_id);
+	  psFree(output);
+	  return false;
+        }
+	
         psFree(row);
-    }
-    }
-
-    if (strcmp(stage,"skycal") == 0) {
+      }
+    }
+    else if (strcmp(stage,"skycal") == 0) {
       for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
-
+	
         skycalRunRow *row = skycalRunObjectFromMetadata(md);
 
@@ -578,5 +554,5 @@
 	  return false;
         }
-
+	
 	if (!dvodb) {  // there's no skycalRun.dvodb
  	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, skycal_id %" PRId64, row->label, row->skycal_id);
@@ -589,14 +565,12 @@
 	  return false;
         }
-
+	
         psFree(row);
       }
     }
-
-    if (strcmp(stage,"diff") == 0) {
-      
+    else if (strcmp(stage,"diff") == 0) {
       for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
-
+	
         diffRunRow *row = diffRunObjectFromMetadata(md);
 	
@@ -606,5 +580,5 @@
 	  return false;
         }
-
+	
 	if (!dvodb) {  // there's no skycalRun.dvodb
  	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, diff_id %" PRId64, row->label, row->diff_id);
@@ -617,15 +591,14 @@
 	  return false;
         }
-
+	
         psFree(row);
       }
     }
-
-    if (strcmp(stage,"fullforce") == 0) {
+    else if (strcmp(stage,"fullforce") == 0) {
       for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
-
+	
         fullForceRunRow *row = fullForceRunObjectFromMetadata(md);
-
+	
         if (!row) {
 	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fullforceRun");
@@ -644,15 +617,14 @@
 	  return false;
         }
-
+	
         psFree(row);
       }
     }
-
-    if (strcmp(stage,"fullforce_summary") == 0) {
+    else if (strcmp(stage,"fullforce_summary") == 0) {
       for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 	//i believe this is correct for ff_summary as well:
         fullForceRunRow *row = fullForceRunObjectFromMetadata(md);
-
+	
         if (!row) {
 	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fullforceRun");
@@ -660,5 +632,5 @@
 	  return false;
         }
-
+	
 	if (!dvodb) {  // there's no skycalRun.dvodb
  	  psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, ff_id %" PRId64, row->label, row->ff_id);
@@ -671,9 +643,9 @@
 	  return false;
         }
-
+	
         psFree(row);
       }
     }
-
+    
 
     // start a transaction so we don't end up with an exp without any associted
@@ -690,19 +662,20 @@
     // old values in place (i.e., passing the values through).
 
-    // loop over our list of camRun rows
+    
     if (strcmp(stage,"cam") == 0) {
-    for (long i = 0; i < psArrayLength(output); i++) {
+      // loop over our list of camRun rows
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 	psS64 stage_id =0; 
 	
-		  camRunRow *row = camRunObjectFromMetadata(md);
-	  stage_id = row->cam_id;
+	camRunRow *row = camRunObjectFromMetadata(md);
+	stage_id = row->cam_id;
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
+	  psFree(output);
+	  return false;
+        }
+	
         // queue the exp
         if (!pxaddQueueByCamID(config,
@@ -720,31 +693,31 @@
                                minidvodb_group,
                                minidvodb_name
-        )) {
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error sfg");
-            }
-            psError(PS_ERR_UNKNOWN, false,
-                    "failed to trying to queue stage %s %" PRId64,stage, stage_id);
-            psFree(row);
-            psFree(output);
-            return false;
+			       )) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error sfg");
+	  }
+	  psError(PS_ERR_UNKNOWN, false,
+		  "failed to trying to queue stage %s %" PRId64,stage, stage_id);
+	  psFree(row);
+	  psFree(output);
+	  return false;
         }
         psFree(row);
-    }
-      }
-    if (strcmp(stage,"stack") == 0) {
-    for (long i = 0; i < psArrayLength(output); i++) {
+      }
+    }
+    else if (strcmp(stage,"stack") == 0) {
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 	psS64 stage_id =0; 
 	
-		  stackRunRow *row = stackRunObjectFromMetadata(md);
-	  stage_id = row->stack_id;
+	stackRunRow *row = stackRunObjectFromMetadata(md);
+	stage_id = row->stack_id;
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
+	  psFree(output);
+	  return false;
+        }
+	
         // queue the exp
         if (!pxaddQueueByCamID(config,
@@ -762,20 +735,19 @@
                                minidvodb_group,
                                minidvodb_name
-        )) {
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error sfg");
-            }
-            psError(PS_ERR_UNKNOWN, false,
-                    "failed to trying to queue stage %s %" PRId64,stage, stage_id);
-            psFree(row);
-            psFree(output);
-            return false;
+			       )) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error sfg");
+	  }
+	  psError(PS_ERR_UNKNOWN, false,
+		  "failed to trying to queue stage %s %" PRId64,stage, stage_id);
+	  psFree(row);
+	  psFree(output);
+	  return false;
         }
         psFree(row);
-    }
-      }
-   
-    if (strcmp(stage,"staticsky") == 0) {
-    for (long i = 0; i < psArrayLength(output); i++) {
+      }
+    }
+    else if (strcmp(stage,"staticsky") == 0) {
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 	psS64 stage_id =0; 
@@ -783,5 +755,5 @@
 	//psS32 num_inputs = psMetadataLookupS32(&status, md, "num_inputs");
 	psS32 stack_id = psMetadataLookupS32(&status, md, "stack_id");
-
+	
 	if (!status) {
 	  psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id");
@@ -792,12 +764,12 @@
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
+	  psFree(output);
+	  return false;
+        }
+	
         // queue the exp
       	//for (int filter_id = 0; filter_id < num_inputs; filter_id++) {  
-	  if (!pxaddQueueByCamID(config,
+	if (!pxaddQueueByCamID(config,
 			       stage,
 			       stage_id,
@@ -813,33 +785,32 @@
                                minidvodb_group,
                                minidvodb_name
-				 )) {
-            if (!psDBRollback(config->dbh)) {
-	      psError(PS_ERR_UNKNOWN, false, "database error sfg");
-            }
-            psError(PS_ERR_UNKNOWN, false,
-                    "failed to trying to queue stage %s %" PRId64,stage, stage_id);
-            psFree(row);
-            psFree(output);
-            return false;
+			       )) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error sfg");
 	  }
-	  //}
+	  psError(PS_ERR_UNKNOWN, false,
+		  "failed to trying to queue stage %s %" PRId64,stage, stage_id);
+	  psFree(row);
+	  psFree(output);
+	  return false;
+	}
+	//}
         psFree(row);
-    }
-      }
-
-    if (strcmp(stage,"skycal") == 0) {
-    for (long i = 0; i < psArrayLength(output); i++) {
+      }
+    }
+    else if (strcmp(stage,"skycal") == 0) {
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 	psS64 stage_id =0; 
 	
-		  skycalRunRow *row = skycalRunObjectFromMetadata(md);
-	  stage_id = row->skycal_id;
+	skycalRunRow *row = skycalRunObjectFromMetadata(md);
+	stage_id = row->skycal_id;
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");
+	  psFree(output);
+	  return false;
+        }
+	
         // queue the exp
         if (!pxaddQueueByCamID(config,
@@ -857,21 +828,19 @@
                                minidvodb_group,
                                minidvodb_name
-        )) {
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error sfg");
-            }
-            psError(PS_ERR_UNKNOWN, false,
-                    "failed to trying to queue stage %s %" PRId64,stage, stage_id);
-            psFree(row);
-            psFree(output);
-            return false;
+			       )) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error sfg");
+	  }
+	  psError(PS_ERR_UNKNOWN, false,
+		  "failed to trying to queue stage %s %" PRId64,stage, stage_id);
+	  psFree(row);
+	  psFree(output);
+	  return false;
         }
         psFree(row);
-    }
-      }
-   
-    if (strcmp(stage,"diff") == 0) {
-      
-    for (long i = 0; i < psArrayLength(output); i++) {
+      }
+    }
+    else if (strcmp(stage,"diff") == 0) {
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 	psS64 stage_id =0; 
@@ -885,10 +854,9 @@
 	  return false;
 	}
-
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");
-            psFree(output);
-            return false;
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");
+	  psFree(output);
+	  return false;
         }
 	
@@ -908,20 +876,19 @@
                                minidvodb_group,
                                minidvodb_name
-        )) {
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error sfg");
-            }
-            psError(PS_ERR_UNKNOWN, false,
-                    "failed to trying to queue stage %s %" PRId64,stage, stage_id);
-            psFree(row);
-            psFree(output);
-            return false;
+			       )) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error sfg");
+	  }
+	  psError(PS_ERR_UNKNOWN, false,
+		  "failed to trying to queue stage %s %" PRId64,stage, stage_id);
+	  psFree(row);
+	  psFree(output);
+	  return false;
         }
         psFree(row);
-    }
-      }
- 
-    if (strcmp(stage,"fullforce") == 0) {
-    for (long i = 0; i < psArrayLength(output); i++) {
+      }
+    }
+    else if (strcmp(stage,"fullforce") == 0) {
+      for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
 	psS64 stage_id =0; 
@@ -935,11 +902,11 @@
 	  return false;
 	}
-
+	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into skycalRun");
+	  psFree(output);
+	  return false;
+        }
+	
         // queue the exp
         if (!pxaddQueueByCamID(config,
@@ -957,18 +924,18 @@
                                minidvodb_group,
                                minidvodb_name
-        )) {
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error sfg");
-            }
-            psError(PS_ERR_UNKNOWN, false,
-                    "failed to trying to queue stage %s %" PRId64,stage, stage_id);
-            psFree(row);
-            psFree(output);
-            return false;
+			       )) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error sfg");
+	  }
+	  psError(PS_ERR_UNKNOWN, false,
+		  "failed to trying to queue stage %s %" PRId64,stage, stage_id);
+	  psFree(row);
+	  psFree(output);
+	  return false;
         }
         psFree(row);
-    }
-    }
-    if (strcmp(stage,"fullforce_summary") == 0) {
+      }
+    }
+    else if (strcmp(stage,"fullforce_summary") == 0) {
       for (long i = 0; i < psArrayLength(output); i++) {
         psMetadata *md = output->data[i];
@@ -979,9 +946,9 @@
 	
         if (!row) {
-            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fullforceRun");
-            psFree(output);
-            return false;
-        }
-
+	  psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fullforceRun");
+	  psFree(output);
+	  return false;
+        }
+	
         // queue the exp
         if (!pxaddQueueByCamID(config,
@@ -999,22 +966,17 @@
                                minidvodb_group,
                                minidvodb_name
-        )) {
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error sfg");
-            }
-            psError(PS_ERR_UNKNOWN, false,
-                    "failed to trying to queue stage %s %" PRId64,stage, stage_id);
-            psFree(row);
-            psFree(output);
-            return false;
+			       )) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error sfg");
+	  }
+	  psError(PS_ERR_UNKNOWN, false,
+		  "failed to trying to queue stage %s %" PRId64,stage, stage_id);
+	  psFree(row);
+	  psFree(output);
+	  return false;
         }
         psFree(row);
-    }
-      }
-
-
-
-
-
+      }
+    }
     psFree(output);
 
@@ -1054,23 +1016,23 @@
     }
     psString query = NULL;
-    if (strcmp(stage, "cam")==0) {
+    if (strcmp(stage, "cam") == 0) {
       query = psStringCopy("UPDATE addRun JOIN camRun on (cam_id = stage_id and stage = 'cam')  JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)");
     }
-    if (strcmp(stage, "stack")==0) {
+    else if (strcmp(stage, "stack") == 0) {
       query = psStringCopy("UPDATE addRun JOIN stackRun on (stack_id = stage_id and stage = 'stack')");
     }
-    if (strcmp(stage, "staticsky")==0) {
+    else if (strcmp(stage, "staticsky") == 0) {
       query = psStringCopy("UPDATE addRun JOIN staticskyRun on (sky_id = stage_id and stage = 'staticsky')");
     }
-    if (strcmp(stage, "skycal")==0) {
+    else if (strcmp(stage, "skycal") == 0) {
       query = psStringCopy("UPDATE addRun JOIN skycalRun on (skycal_id = stage_id and stage = 'skycal')");
     }
-    if (strcmp(stage, "diff")==0) {
+    else if (strcmp(stage, "diff") == 0) {
       query = psStringCopy("UPDATE addRun JOIN diffInputSkyfile on (diff_id = stage_id and diff_skyfile_id = stage_extra1 and stage = 'diff') JOIN diffSkyfile on (diff_id, skycell_id) JOIN diffRun using (diff_id)");
     }
-    if (strcmp(stage, "fullforce")==0) {
+    else if (strcmp(stage, "fullforce") == 0) {
       query = psStringCopy("UPDATE addRun JOIN fullForceResult on (ff_id = stage_id and warp_id = stage_extra1 and stage = 'fullforce') JOIN fullForceRun on (ff_id)");
     }
-    if (strcmp(stage, "fullforce_summary")==0) {
+    else if (strcmp(stage, "fullforce_summary") == 0) {
       query = psStringCopy("UPDATE addRun JOIN fullForceSummary on (ff_id = stage_id and stage = 'fullforce_summary') JOIN fullForceRun on (ff_id)");
     }
@@ -1112,23 +1074,23 @@
     psString query = NULL;
     
-    if (strcmp(stage, "cam")==0) { 
+    if (strcmp(stage, "cam") == 0) { 
       query = pxDataGet("addtool_find_pendingexp_cam.sql");
     }
-    if (strcmp(stage, "stack")==0) { 
+    else if (strcmp(stage, "stack") == 0) { 
       query = pxDataGet("addtool_find_pendingexp_stack.sql");
     }
-    if (strcmp(stage, "staticsky")==0) { 
+    else if (strcmp(stage, "staticsky") == 0) { 
       query = pxDataGet("addtool_find_pendingexp_staticsky_multi.sql");
     }
-    if (strcmp(stage, "skycal")==0) {
+    else if (strcmp(stage, "skycal") == 0) {
       query = pxDataGet("addtool_find_pendingexp_skycal.sql");
     }
-    if (strcmp(stage, "diff")==0) {
+    else if (strcmp(stage, "diff") == 0) {
       query = pxDataGet("addtool_find_pendingexp_diff.sql");
     }
-    if (strcmp(stage, "fullforce")==0) {
+    else if (strcmp(stage, "fullforce") == 0) {
       query = pxDataGet("addtool_find_pendingexp_ff.sql");
     }
-    if (strcmp(stage, "fullforce_summary")==0) {
+    else if (strcmp(stage, "fullforce_summary") == 0) {
       query = pxDataGet("addtool_find_pendingexp_ffsummary.sql");
     }
@@ -1151,21 +1113,21 @@
       psStringAppend(&query, " GROUP BY %s", "stack_id");
     }
-    if (strcmp(stage, "skycal") == 0) {
+    else if (strcmp(stage, "skycal") == 0) {
       //this group by is needed to join against all the warps (to get camera)
       psStringAppend(&query, " GROUP BY %s", "skycal_id");
     }
-    if (strcmp(stage, "staticsky") == 0) {
+    else if (strcmp(stage, "staticsky") == 0) {
       //this group by is needed to join against all the warps (to get camera)
       psStringAppend(&query, " GROUP BY %s", "sky_id, stage_extra1");
     }
-    if (strcmp(stage, "diff") == 0) {
+    else if (strcmp(stage, "diff") == 0) {
       //this group by is needed to join against all the warps (to get camera)
       if (multiadd) {
 	psStringAppend(&query, " GROUP BY %s", "diff_id");
       } else {
-      psStringAppend(&query, " GROUP BY %s", "diff_id, stage_extra1");
-      }
-    }
-    if (strcmp(stage, "fullforce") == 0) {
+	psStringAppend(&query, " GROUP BY %s", "diff_id, stage_extra1");
+      }
+    }
+    else if (strcmp(stage, "fullforce") == 0) {
       //this group by is needed to join against all the warps (to get camera)
       if (multiadd) {
@@ -1175,6 +1137,5 @@
       }
     }
-    
-    if (strcmp(stage, "fullforce_summary") == 0) {
+    else if (strcmp(stage, "fullforce_summary") == 0) {
       //this group by is needed to join against all the warps (to get camera)
       psStringAppend(&query, "GROUP BY %s", "ff_id");
@@ -1183,37 +1144,37 @@
     // treat limit == 0 as "no limit"
     if (limit) {
-        psString limitString = psDBGenerateLimitSQL(limit);
-        psStringAppend(&query, " %s", limitString);
-        psFree(limitString);
+      psString limitString = psDBGenerateLimitSQL(limit);
+      psStringAppend(&query, " %s", limitString);
+      psFree(limitString);
     }
     if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      psFree(query);
+      return false;
     }
     //    printf ("%s\n", query);
     //psTrace("addtool.c", PS_LOG_INFO, "used this query:\n %s\n",query); 
     psFree(query);
-
+    
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      return false;
     }
     if (!psArrayLength(output)) {
-        psTrace("addtool", PS_LOG_INFO, "no rows found");
-        psFree(output);
-        return true;
-    }
-
+      psTrace("addtool", PS_LOG_INFO, "no rows found");
+      psFree(output);
+      return true;
+    }
+    
     // negate simple so the default is true
     if (!ippdbPrintMetadatas(stdout, output, "addPendingExp", !simple)) {
-        psError(PS_ERR_UNKNOWN, false, "failed to print array");
-        psFree(output);
-        return false;
-    }
-
+      psError(PS_ERR_UNKNOWN, false, "failed to print array");
+      psFree(output);
+      return false;
+    }
+    
     psFree(output);
-
+    
     return true;
 }
@@ -1222,8 +1183,8 @@
 {
     PS_ASSERT_PTR_NON_NULL(config, false);
-
+  
     // required
     // PXOPT_LOOKUP_S64(add_id, config->args, "-add_id", true, false);
-
+    
     // optional
     PXOPT_LOOKUP_STR(path_base,     config->args, "-path_base", false, false);
@@ -1233,5 +1194,5 @@
     PXOPT_LOOKUP_S16(fault,         config->args, "-fault", false, false);
     PXOPT_LOOKUP_S64(stage_extra1, config->args, "-stage_extra1", false, false);
-
+    
     PXOPT_LOOKUP_BOOL(multiadd, config->args, "-multiadd", false);
     // generate restrictions
@@ -1256,62 +1217,61 @@
     psString query = pxDataGet("addtool_find_pendingexp.sql");
     if (!query) {
-        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
-        return false;
-    }
-
+      psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+      return false;
+    }
+    
     // use psDBGenerateWhereSQL because the SQL yields an intermediate table
     if (psListLength(where->list)) {
-        psString whereClaus = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClaus);
-        psFree(whereClaus);
+      psString whereClaus = psDBGenerateWhereConditionSQL(where, NULL);
+      psStringAppend(&query, " AND %s", whereClaus);
+      psFree(whereClaus);
     }
     psFree(where);
-
+    
     //if (multiadd) {
     //  psStringAppend(&query, "group by  %s", "stage_extra1");
     //}
-
+    
     if (!p_psDBRunQuery(config->dbh, query)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(query);
-        return false;
-    }
-
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      psFree(query);
+      return false;
+    }
+    
     psFree(query);
-
+    
     psArray *output = p_psDBFetchResult(config->dbh);
     if (!output) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      return false;
     }
     
     if (!psArrayLength(output)) {
-        psTrace("addtool", PS_LOG_INFO, "no rows found");
-        psFree(output);
-        return false;
-    }
-
+      psTrace("addtool", PS_LOG_INFO, "no rows found");
+      psFree(output);
+      return false;
+    }
+    
     if (!psDBTransaction(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(output);
-        return false;
-    }
-
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      psFree(output);
+      return false;
+    }
+    
     for (long i =0; i<psArrayLength(output);i++) {
+      addRunRow *pendingRow = addRunObjectFromMetadata(output->data[i]);
       
-    addRunRow *pendingRow = addRunObjectFromMetadata(output->data[i]);
-    
-    addProcessedExpRow *row = addProcessedExpRowAlloc(
-        pendingRow->add_id,
-        dtime_addstar,
-        path_base,
-        dvodb_path,
-        fault
-        );
-
-    if (!addProcessedExpInsertObject(config->dbh, row)) {
+      addProcessedExpRow *row = addProcessedExpRowAlloc(
+							pendingRow->add_id,
+							dtime_addstar,
+							path_base,
+							dvodb_path,
+							fault
+							);
+      
+      if (!addProcessedExpInsertObject(config->dbh, row)) {
         // rollback
         if (!psDBRollback(config->dbh)) {
-            psError(PS_ERR_UNKNOWN, false, "database error");
+	  psError(PS_ERR_UNKNOWN, false, "database error");
         }
         psError(PS_ERR_UNKNOWN, false, "database error");
@@ -1319,58 +1279,58 @@
         psFree(pendingRow);
         return false;
-    }
-
-    //if there is a minidvodb_name, set it in addRun (it's not known until it is processed)
-    if (minidvodb_name) {
-      psString setName = NULL;
-      psStringAppend (&setName, "UPDATE addRun set minidvodb_name = '%s' where add_id = %" PRId64, minidvodb_name, row->add_id);
-      if (!p_psDBRunQuery(config->dbh, setName)) {
-        if (!psDBRollback(config->dbh)) {
-          psError(PS_ERR_UNKNOWN, false, "database error");
-        }
+      }
+      
+      //if there is a minidvodb_name, set it in addRun (it's not known until it is processed)
+      if (minidvodb_name) {
+	psString setName = NULL;
+	psStringAppend (&setName, "UPDATE addRun set minidvodb_name = '%s' where add_id = %" PRId64, minidvodb_name, row->add_id);
+	if (!p_psDBRunQuery(config->dbh, setName)) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error");
+	  }
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	  
+	  return false;
+	}
+      }
+      //if there is a stage_extra1, set it in addRun (it's not known until it is processed)
+      if (stage_extra1) {
+	psString setExtra = NULL;
+	psStringAppend (&setExtra, "UPDATE addRun set stage_extra1 = %" PRId64, stage_extra1);
+	psStringAppend (&setExtra, " where add_id = %" PRId64, row->add_id);
+	
+	if (!p_psDBRunQuery(config->dbh, setExtra)) {
+	  if (!psDBRollback(config->dbh)) {
+	    psError(PS_ERR_UNKNOWN, false, "database error");
+	  }
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	  
+	  return false;
+	}
+      }
+      
+      
+      
+      
+      // since there is only one exp per 'new' set addRun.state = 'full'
+      // but check to make sure there are no faults
+      
+      if (!fault) {
+	if (!pxaddRunSetState(config, row->add_id, "full")) {
+	  psError(PS_ERR_UNKNOWN, false, "failed to change addRun.state for add_id: %" PRId64, row->add_id);
+	  psFree(row);
+	  psFree(pendingRow);
+	  return false;
+	}
+      }
+      psFree(row);
+      psFree(pendingRow);
+      
+      if (!psDBCommit(config->dbh)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
-
-        return false;
-      }
-    }
-    //if there is a stage_extra1, set it in addRun (it's not known until it is processed)
-    if (stage_extra1) {
-      psString setExtra = NULL;
-      psStringAppend (&setExtra, "UPDATE addRun set stage_extra1 = %" PRId64, stage_extra1);
-      psStringAppend (&setExtra, " where add_id = %" PRId64, row->add_id);
-
-      if (!p_psDBRunQuery(config->dbh, setExtra)) {
-        if (!psDBRollback(config->dbh)) {
-          psError(PS_ERR_UNKNOWN, false, "database error");
-        }
-        psError(PS_ERR_UNKNOWN, false, "database error");
-
-        return false;
-      }
-    }
-
-
-
-
-    // since there is only one exp per 'new' set addRun.state = 'full'
-    // but check to make sure there are no faults
-
-    if (!fault) {
-      if (!pxaddRunSetState(config, row->add_id, "full")) {
-        psError(PS_ERR_UNKNOWN, false, "failed to change addRun.state for add_id: %" PRId64, row->add_id);
-        psFree(row);
-        psFree(pendingRow);
-        return false;
-      }
-    }
-    psFree(row);
-    psFree(pendingRow);
-
-    if (!psDBCommit(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-    }
-
+        return false;
+      }
+    }
+    
     return true;
 }
@@ -1507,80 +1467,77 @@
     pxAddLabelSearchArgs (config, where, "-label",    "addRun.label",     "==");
     PXOPT_COPY_STR(config->args, where, "-reduction", "addRun.reduction",      "==");
-
+    
     if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
-        psFree(where);
-        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
-        return false;
-    }
-
+      psFree(where);
+      psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
+      return false;
+    }
+    
     if (!psDBTransaction(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        psFree(where);
-        return false;
-    }
-
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      psFree(where);
+      return false;
+    }
+    
     {
       psString query = NULL;
       if (strcmp(stage, "cam") == 0) {
-         query = pxDataGet("addtool_revertprocessedexp_cam.sql");
-	}
-	
-    if (strcmp(stage, "stack") == 0) {
-	 query = pxDataGet("addtool_revertprocessedexp_stack.sql");
-      }
-    if (strcmp(stage, "staticsky") == 0) {
-	 query = pxDataGet("addtool_revertprocessedexp_staticsky_multi.sql");
-      }
-    if (strcmp(stage, "skycal") == 0) {
-      query = pxDataGet("addtool_revertprocessedexp_skycal.sql");
-    }
-    if (strcmp(stage, "diff") == 0) {
-      query = pxDataGet("addtool_revertprocessedexp_diff.sql");
-    }
-    if (strcmp(stage, "fullforce") == 0) {
-      query = pxDataGet("addtool_revertprocessedexp_ff.sql");
-    }
-    if (strcmp(stage, "fullforce_summary") == 0) {
-      query = pxDataGet("addtool_revertprocessedexp_ffsummary.sql");
-    }
-
-
+	query = pxDataGet("addtool_revertprocessedexp_cam.sql");
+      }
+      else if (strcmp(stage, "stack") == 0) {
+	query = pxDataGet("addtool_revertprocessedexp_stack.sql");
+      }
+      else if (strcmp(stage, "staticsky") == 0) {
+	query = pxDataGet("addtool_revertprocessedexp_staticsky_multi.sql");
+      }
+      else if (strcmp(stage, "skycal") == 0) {
+	query = pxDataGet("addtool_revertprocessedexp_skycal.sql");
+      }
+      else if (strcmp(stage, "diff") == 0) {
+	query = pxDataGet("addtool_revertprocessedexp_diff.sql");
+      }
+      else if (strcmp(stage, "fullforce") == 0) {
+	query = pxDataGet("addtool_revertprocessedexp_ff.sql");
+      }
+      else if (strcmp(stage, "fullforce_summary") == 0) {
+	query = pxDataGet("addtool_revertprocessedexp_ffsummary.sql");
+      }
      
       if (!query) {
-            // rollback
+	// rollback
 	if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error");
-            }
-            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
-            psFree(where);
-            return false;
-        }
-
-        // use psDBGenerateWhereConditionalSQL with AND ... because the SQL ends in a WHERE
-        if (where && psListLength(where->list)) {
-            psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-            psStringAppend(&query, " AND %s", whereClause);
-            psFree(whereClause);
-        }
-
-        if (!p_psDBRunQuery(config->dbh, query)) {
-            // rollback
-            if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error");
-            }
-            psError(PS_ERR_UNKNOWN, false, "database error");
-            psFree(query);
-            psFree(where);
-            return false;
-        }
-        psFree(query);
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	}
+	psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+	psFree(where);
+	return false;
+      }
+      
+      // use psDBGenerateWhereConditionalSQL with AND ... because the SQL ends in a WHERE
+      if (where && psListLength(where->list)) {
+	psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
+	psStringAppend(&query, " AND %s", whereClause);
+	psFree(whereClause);
+      }
+      
+      if (!p_psDBRunQuery(config->dbh, query)) {
+	// rollback
+	if (!psDBRollback(config->dbh)) {
+	  psError(PS_ERR_UNKNOWN, false, "database error");
+	}
+	psError(PS_ERR_UNKNOWN, false, "database error");
+	psFree(query);
+	psFree(where);
+	return false;
+      }
+      psFree(query);
     }
     psFree(where);
-
+    
     if (!psDBCommit(config->dbh)) {
-        psError(PS_ERR_UNKNOWN, false, "database error");
-        return false;
-    }
-
+      psError(PS_ERR_UNKNOWN, false, "database error");
+      return false;
+    }
+    
     return true;
 }
@@ -1682,7 +1639,7 @@
 
   // required
-
   PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-set_minidvodb_group", true, false);
-    //optional
+
+  //optional
   PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-set_minidvodb_name", false, false);
   PXOPT_LOOKUP_STR(minidvodb_path, config->args, "-set_minidvodb_path", false, false);
@@ -1703,17 +1660,17 @@
     return false;
   }
-
+  
   if (!minidvodbRunInsert(config->dbh,
-            0, // job_id
-            minidvodb_name,
-            minidvodb_group,
-            minidvodbpath,
-	    "new",
-            0
-            )) {
+			  0, // job_id
+			  minidvodb_name,
+			  minidvodb_group,
+			  minidvodbpath,
+			  "new",
+			  0
+			  )) {
     psError(PS_ERR_UNKNOWN, false, "database error");
     return false;
   }
-
+  
   psU64 affected = psDBAffectedRows(config->dbh);
   if (affected != 1) {
@@ -1723,9 +1680,9 @@
     return false;
   }
-
+  
   psS64 minidvodb_id = psDBLastInsertID(config->dbh);
   printf("%" PRId64 "\n", minidvodb_id);
 
-
+  
   if (!minidvodb_name) {
     psStringAppend(&minidvodb_name, "%s.%" PRIu64,minidvodb_group,minidvodb_id);
@@ -1734,5 +1691,4 @@
     psStringAppend(&minidvodb_path,"/%s",minidvodb_name);
   }
-
 
   psString query = NULL;
@@ -1786,7 +1742,7 @@
     if (minidvodb_path) {
       if (cnt) {
-          psStringAppend(&query, "%s", comma);
-      }
-
+	psStringAppend(&query, "%s", comma);
+      }
+      
       psStringAppend(&query, " minidvodb_path = '%s'", minidvodb_path);
       cnt++;
@@ -1910,11 +1866,11 @@
     }
     psFree(query);
-  return false;
-  }
- psFree(query2);
- psFree(where);
-
- return true;
-
+    return false;
+  }
+  psFree(query2);
+  psFree(where);
+  
+  return true;
+ 
 }
 
@@ -1936,7 +1892,7 @@
 
   if (!psListLength(where->list)) {
-        psFree(where);
-        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
-        return false;
+    psFree(where);
+    psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
+    return false;
   }
 
@@ -1950,6 +1906,6 @@
   
   if (!bare_query) {
-        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
-        return false;
+    psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+    return false;
   }
 
@@ -1957,7 +1913,7 @@
   if (psListLength(where->list)) {
     psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&where_string, " WHERE %s", whereClause);
-        psFree(whereClause);
-	//search params are defined above
+    psStringAppend(&where_string, " WHERE %s", whereClause);
+    psFree(whereClause);
+    //search params are defined above
   }
 
@@ -1966,8 +1922,4 @@
   psStringAppend(&query," %s ", where_string);
 
-
-
-
-  
   if (!all_addrun_states) {
     psStringAppend(&query, " AND (cnt2 = cnt) ");
@@ -2082,9 +2034,9 @@
   PS_ASSERT_PTR_NON_NULL(config, false);
 
-    // required
+  // required
   // PXOPT_LOOKUP_U64(minidvodb_id, config->args, "-minidvodb_id", true, false);
   PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-minidvodb_group", true, false);
 
-    // optional
+  // optional
   PXOPT_LOOKUP_F32(dtime_relphot, config->args, "-dtime_relphot", false, false);
   PXOPT_LOOKUP_F32(dtime_resort, config->args, "-dtime_resort", false, false);
@@ -2093,5 +2045,6 @@
   PXOPT_LOOKUP_TIME(epoch, config->args, "-epoch", false, false);
   PXOPT_LOOKUP_S16(fault,         config->args, "-fault", false, false);
-    //generate restrictions
+
+  //generate restrictions
   psMetadata *where = psMetadataAlloc();
   PXOPT_COPY_S64(config->args, where, "-minidvodb_id",   "minidvodbRun.minidvodb_id",   "==");
@@ -2138,12 +2091,12 @@
   psFree(output);
   minidvodbProcessedRow *row = minidvodbProcessedRowAlloc(
-               pendingRow->minidvodb_id,
-               dtime_resort,
-               dtime_relphot,
-	       dtime_script,
-               epoch,
-               fault
-               );
-
+							  pendingRow->minidvodb_id,
+							  dtime_resort,
+							  dtime_relphot,
+							  dtime_script,
+							  epoch,
+							  fault
+							  );
+  
   if (!minidvodbProcessedInsertObject(config->dbh, row)) {
     // rollback
@@ -2171,8 +2124,4 @@
   psFree(row);
   psFree(pendingRow);
-
-
-
-
 
   //commit the changes
@@ -2342,5 +2291,5 @@
   PXOPT_LOOKUP_F32(dtime_relphot,  config->args, "-set_dtime_relphot", false, false);
   PXOPT_LOOKUP_F32(dtime_resort,  config->args, "-set_dtime_resort", false, false);
-PXOPT_LOOKUP_F32(dtime_script,  config->args, "-set_dtime_script", false, false);
+  PXOPT_LOOKUP_F32(dtime_script,  config->args, "-set_dtime_script", false, false);
   PXOPT_COPY_S64(config->args, where, "-minidvodb_id",     "minidvodbProcessed.minidvodb_id", "==");
   PXOPT_COPY_STR(config->args, where, "-minidvodb_name",     "minidvodbRun.minidvodb_name", "==");
