Index: /branches/eam_branches/ipp-20100621/ppSub/src/ppSubBackground.c
===================================================================
--- /branches/eam_branches/ipp-20100621/ppSub/src/ppSubBackground.c	(revision 28947)
+++ /branches/eam_branches/ipp-20100621/ppSub/src/ppSubBackground.c	(revision 28948)
@@ -67,15 +67,17 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
+	    // special case 1: NAN the masked pixels
             if (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskBad) {
-                image->data.F32[y][x] = 0.0;
-            } else {
-                float value = psImageUnbinPixel(x + 0.5, y + 0.5, modelImage, binning); // Background value
-                if (!isfinite(value)) {
-                    image->data.F32[y][x] = NAN;
-                    mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskBad;
-                } else {
-                    image->data.F32[y][x] -= value;
-                }
-            }
+                image->data.F32[y][x] = NAN;
+		continue;
+            } 
+	    // special case 1: NAN & mask pixels without a valid background model
+	    float value = psImageUnbinPixel(x + 0.5, y + 0.5, modelImage, binning); // Background value
+	    if (!isfinite(value)) {
+	      image->data.F32[y][x] = NAN;
+	      mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskBad;
+	      continue;
+	    } 
+	    image->data.F32[y][x] -= value;
         }
     }
Index: /branches/eam_branches/ipp-20100621/ppSub/src/ppSubLoop.c
===================================================================
--- /branches/eam_branches/ipp-20100621/ppSub/src/ppSubLoop.c	(revision 28947)
+++ /branches/eam_branches/ipp-20100621/ppSub/src/ppSubLoop.c	(revision 28948)
@@ -17,6 +17,16 @@
 #include <pslib.h>
 #include <psmodules.h>
+#include <psphot.h>
 
 #include "ppSub.h"
+
+bool dumpout(pmConfig *config, char *name) 
+{
+  pmFPAview *view = ppSubViewReadout(); // View to readout
+  pmReadout *out = pmFPAfileThisReadout(config->files, view, "PPSUB.OUTPUT");
+  psphotSaveImage (NULL, out->image, name);
+  return true;
+}
+
 
 bool ppSubLoop(ppSubData *data)
@@ -105,4 +115,5 @@
         return false;
     }
+    // dumpout(config, "diff.1.fits");
 
     // Close convolved files
@@ -111,4 +122,5 @@
         return false;
     }
+    // dumpout(config, "diff.2a.fits");
 
     // Higher order background subtraction using psphot
@@ -117,4 +129,5 @@
         return false;
     }
+    // dumpout(config, "diff.2b.fits");
 
     // Perform Variance correction (rescale within a modest range)
@@ -123,4 +136,5 @@
         return false;
     }
+    // dumpout(config, "diff.2c.fits");
 
     if (data->quality) {
@@ -138,4 +152,5 @@
         return false;
     }
+    // dumpout(config, "diff.3.fits");
 
     if (!ppSubFilesIterateUp(config, PPSUB_FILES_PHOT_SUB)) {
@@ -157,4 +172,5 @@
       }
     }
+    // dumpout(config, "diff.4.fits");
     
     // generate the binned image used to write the jpeg
@@ -204,4 +220,5 @@
     } else {
         // Close subtraction files
+	// dumpout(config, "diff.5.fits");
         if (!ppSubFilesIterateUp(config, PPSUB_FILES_SUB)) {
             psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
