Index: trunk/psModules/src/imcombine/pmSubtraction.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtraction.c	(revision 19344)
+++ trunk/psModules/src/imcombine/pmSubtraction.c	(revision 19357)
@@ -446,16 +446,13 @@
 
     // Get bounds of threshold region
-    // Start with the entire kernel, and keep reducing the size of the box until it drops below threshold
-    int box = kernels->size;                    // Size of box with bad pixels
-    for (double sumBox = sumKernel2; box > 0; box--) {
+    // Start with the entire kernel, and keep reducing the size of the box until it sum goes above threshold
+    int box = kernels->size;            // Size of box with bad pixels
+    for (double sumBox = 0.0; sumBox < threshold && box > 0; box--) {
         for (int x = -box; x <= box; x++) {
-            sumBox -= PS_SQR(kernel->kernel[-box][x]) + PS_SQR(kernel->kernel[box][x]);
+            sumBox += PS_SQR(kernel->kernel[-box][x]) + PS_SQR(kernel->kernel[box][x]);
         }
         for (int y = -box + 1; y <= box - 1; y++) {
             // Note: not doing corners
-            sumBox -= PS_SQR(kernel->kernel[y][-box]) + PS_SQR(kernel->kernel[y][box]);
-        }
-        if (sumBox < threshold) {
-            break;
+            sumBox += PS_SQR(kernel->kernel[y][-box]) + PS_SQR(kernel->kernel[y][box]);
         }
     }
@@ -731,8 +728,8 @@
     }
 
+    psLogMsg("psModules.imcombine", PS_LOG_INFO, "RMS deviation from %d stamps: %lf", numStamps, rms);
+
     if (!isfinite(sigmaRej) || sigmaRej <= 0.0) {
         // User just wanted to calculate and record the RMS for posterity
-        psLogMsg("psModules.imcombine", PS_LOG_INFO, "RMS deviation from %d stamps: %lf",
-                 numStamps, rms);
         return 0;
     }
