Index: trunk/psModules/src/detrend/pmMaskBadPixels.c
===================================================================
--- trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 18364)
+++ trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 18554)
@@ -123,10 +123,11 @@
     psTrace ("psModules.detrend", 3, "suspect: %f +/- %f\n", median, stdev);
 
+    // XXX this loop could result in pixels with suspect = 0.0 but no valid input pixels (all
+    // masked).  need to track the number of good as well as suspect pixels?
     for (int y = 0; y < image->numRows; y++) {
         for (int x = 0; x < image->numCols; x++) {
-            if (fabs((image->data.F32[y][x] - median) / stdev) >= rej &&
-		(!mask || !(mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal))) {
-                suspect->data.F32[y][x] += 1.0;
-            }
+            if (fabs((image->data.F32[y][x] - median) / stdev) < rej) continue;
+	    if (mask && (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal)) continue;
+	    suspect->data.F32[y][x] += 1.0;
         }
     }
@@ -140,4 +141,5 @@
 }
 
+// the maskVal supplied here is the value SET for this mask (ie, it is not used to avoid pixels)
 bool pmMaskIdentifyBadPixels(pmReadout *output, psMaskType maskVal, float thresh, pmMaskIdentifyMode mode)
 {
