Index: branches/eam_branches/ipp-20120905/ippScripts/scripts/background_warp.pl
===================================================================
--- branches/eam_branches/ipp-20120905/ippScripts/scripts/background_warp.pl	(revision 34729)
+++ branches/eam_branches/ipp-20120905/ippScripts/scripts/background_warp.pl	(revision 34735)
@@ -88,5 +88,5 @@
 my $logDest = $ipprc->filename("LOG.EXP", $outroot, $skycell_id) or my_die( "Unable to get log filename", $warp_bg_id, $skycell_id, $PS_EXIT_SYS_ERROR );
 
-$ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $warp_bg_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
+$ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $warp_bg_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
 
 # Recipes to use based on reduction class
@@ -158,11 +158,18 @@
 &my_die("Can't find input astrometry: $astrometry", $warp_bg_id, $skycell_id, $PS_EXIT_PROG_ERROR) unless $ipprc->file_exists($astrometry);
 
-my $out_image = $ipprc->filename("PSWARP.OUTPUT", $outroot, $skycell_id );
-my $out_mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $outroot, $skycell_id);
-my $out_stats = $ipprc->filename("SKYCELL.STATS", $outroot, $skycell_id );
-my $out_config = $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id);
-my $traceDest = $ipprc->filename("TRACE.EXP", $outroot, $skycell_id);
-
-my $skyFile = $ipprc->filename("SKYCELL.TEMPLATE", $outroot, $skycell_id );
+#my $out_image = $ipprc->filename("PSWARP.OUTPUT", $outroot, $skycell_id );
+#my $out_mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $outroot, $skycell_id);
+#my $out_stats = $ipprc->filename("SKYCELL.STATS", $outroot, $skycell_id );
+#my $out_config = $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id);
+#my $traceDest = $ipprc->filename("TRACE.EXP", $outroot, $skycell_id);
+
+my $out_image = prepare_output("PSWARP.OUTPUT", $outroot, $skycell_id,  1);
+my $out_mask = prepare_output("PSWARP.OUTPUT.MASK", $outroot, $skycell_id, 1);
+my $out_stats = prepare_output("SKYCELL.STATS", $outroot, $skycell_id, 1);
+my $out_config = prepare_output("PSWARP.CONFIG", $outroot, $skycell_id, 1);
+my $traceDest = prepare_output("TRACE.EXP", $outroot, $skycell_id, 1);
+
+my $skyFile = prepare_output("SKYCELL.TEMPLATE", $outroot, $skycell_id, 1);
+
 $ipprc->skycell_file( $tess_dir, $skycell_id, $skyFile, $verbose ) or &my_die("Unable to generate template skycell", $warp_bg_id, $skycell_id, $PS_EXIT_SYS_ERROR);
 
@@ -239,4 +246,18 @@
 ### Pau.
 
+sub prepare_output
+{
+    my $filerule = shift;
+    my $outroot  = shift;
+    my $skycell_id = shift;
+    my $delete = shift;
+    $delete = 0 if !defined $delete;
+
+    my $error;
+    my $output = $ipprc->prepare_output($filerule, $outroot, $skycell_id, $delete, \$error)
+                    or &my_die("failed to prepare output file for: $filerule", $warp_bg_id, $skycell_id, $error);
+    return $output;
+}
+
 
 sub my_die
Index: branches/eam_branches/ipp-20120905/ippScripts/scripts/destreak_restore_camera.pl
===================================================================
--- branches/eam_branches/ipp-20120905/ippScripts/scripts/destreak_restore_camera.pl	(revision 34729)
+++ branches/eam_branches/ipp-20120905/ippScripts/scripts/destreak_restore_camera.pl	(revision 34735)
@@ -440,6 +440,6 @@
     }
 
+    my $backup_url = shift;
     my $original_url = shift;
-    my $backup_url = shift;
 
     # rename the backup as the orig
@@ -449,5 +449,5 @@
     my $moved;
     eval {
-        $moved = nebulous->move($backup_url, $original_url);
+        $moved = $nebulous->move($backup_url, $original_url);
     };
     if ($@ or not $moved) {
Index: branches/eam_branches/ipp-20120905/ippScripts/scripts/lap_science.pl
===================================================================
--- branches/eam_branches/ipp-20120905/ippScripts/scripts/lap_science.pl	(revision 34729)
+++ branches/eam_branches/ipp-20120905/ippScripts/scripts/lap_science.pl	(revision 34735)
@@ -671,4 +671,21 @@
 # 	}
 	# Do quality checks here
+	if ($verbose) {
+	    printf("TEST: %d %d %d\n",$exposure->{exp_id},$exposure->{chip_id},$exposure->{chip_component_count});
+	}
+	# Checks to ensure we do not divide by zero.  Mostly happens with old diffs, it seems.
+	if ($exposure->{chip_component_count} == 0) {
+	    $exposure->{chip_component_count} = 1;
+	}
+	if ($exposure->{cam_component_count} == 0) {
+	    $exposure->{cam_component_count} = 1;
+	}
+	if ($exposure->{warp_component_count} == 0) {
+	    $exposure->{warp_component_count} = 1;
+	}
+	if ($exposure->{diff_component_count} == 0) {
+	    $exposure->{diff_component_count} = 1;
+	}
+
 	my $is_bad_quality = 0;
 	if ((defined($exposure->{chipRun_state}))&&($exposure->{chipRun_state} eq 'full')&&
