Index: trunk/ppStack/src/ppStackLoop.c
===================================================================
--- trunk/ppStack/src/ppStackLoop.c	(revision 19214)
+++ trunk/ppStack/src/ppStackLoop.c	(revision 19268)
@@ -12,5 +12,5 @@
 #include "ppStack.h"
 
-//#define TESTING
+#define TESTING
 
 #define WCS_TOLERANCE 0.001             // Tolerance for WCS
@@ -619,6 +619,35 @@
             psLogMsg("ppStack", PS_LOG_INFO, "%ld total pixels to inspect from image %d", inspect->n, i);
 
+#ifdef TESTING
+            {
+                psImage *pix = psPixelsToMask(NULL, inspect, psRegionSet(0, outRO->image->numCols - 1,
+                                                                         0, outRO->image->numRows - 1), 0xff);
+                psString name = NULL;           // Name of image
+                psStringAppend(&name, "inspect_%03d.fits", i);
+                psFits *fits = psFitsOpen(name, "w");
+                psFree(name);
+                psFitsWriteImage(fits, NULL, pix, 0, NULL);
+                psFree(pix);
+                psFitsClose(fits);
+            }
+#endif
+
             psPixels *reject = pmStackReject(inspect, NULL, threshold, subRegions->data[i],
                                              subKernels->data[i]); // Pixels to reject
+
+#ifdef TESTING
+            {
+                psImage *pix = psPixelsToMask(NULL, reject, psRegionSet(0, outRO->image->numCols - 1,
+                                                                        0, outRO->image->numRows - 1), 0xff);
+                psString name = NULL;           // Name of image
+                psStringAppend(&name, "reject_%03d.fits", i);
+                psFits *fits = psFitsOpen(name, "w");
+                psFree(name);
+                psFitsWriteImage(fits, NULL, pix, 0, NULL);
+                psFree(pix);
+                psFitsClose(fits);
+            }
+#endif
+
             psFree(inspect);
             if (!reject) {
@@ -727,4 +756,9 @@
         }
         psFree(readouts);
+
+        // Ensure masked regions really look masked
+        if (!pmReadoutMaskApply(outRO, maskBad)) {
+            psWarning("Unable to apply mask");
+        }
 
         // Close up
