Index: trunk/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 15756)
+++ trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 15787)
@@ -53,5 +53,6 @@
     psFree(stamp->matrix2);
     psFree(stamp->matrixX);
-    psFree(stamp->vector);
+    psFree(stamp->vector1);
+    psFree(stamp->vector2);
 
 }
@@ -173,5 +174,6 @@
     stamp->matrix2 = NULL;
     stamp->matrixX = NULL;
-    stamp->vector = NULL;
+    stamp->vector1 = NULL;
+    stamp->vector2 = NULL;
 
     return stamp;
@@ -348,12 +350,17 @@
         if (!checkStampRegion(xPix, yPix, region)) {
             // It's not in the big region
+            psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because outside region",
+                    xPix, yPix);
             continue;
         }
         if (!checkStampMask(xPix, yPix, subMask, mode)) {
             // Not a good stamp
+            psTrace("psModules.imcombine", 9, "Rejecting input stamp (%d,%d) because bad mask",
+                    xPix, yPix);
             continue;
         }
 
-        for (int j = 0; j < numStamps; j++) {
+        bool found = false;
+        for (int j = 0; j < numStamps && !found; j++) {
             psRegion *subRegion = stamps->regions->data[j]; // Subregion of interest
             if (checkStampRegion(xPix, yPix, subRegion)) {
@@ -362,4 +369,9 @@
 
                 int index = xList->n;   // Index of new stamp candidate
+
+                psVectorExtend(xList, STAMP_LIST_BUFFER, 1);
+                psVectorExtend(yList, STAMP_LIST_BUFFER, 1);
+                psVectorExtend(fluxList, STAMP_LIST_BUFFER, 1);
+
                 xList->data.F32[index] = xStamp;
                 yList->data.F32[index] = yStamp;
@@ -371,10 +383,13 @@
                 }
 
-                psVectorExtend(xList, STAMP_LIST_BUFFER, 1);
-                psVectorExtend(yList, STAMP_LIST_BUFFER, 1);
-                psVectorExtend(fluxList, STAMP_LIST_BUFFER, 1);
-
-                break;
+                found = true;
+                psTrace("psModules.imcombine", 9, "Putting input stamp (%d,%d) into subregion %d",
+                        xPix, yPix, j);
             }
+        }
+
+        if (!found) {
+            psTrace("psModules.imcombine", 9, "Unable to find subregion for stamp (%d,%d)",
+                    xPix, yPix);
         }
     }
@@ -563,7 +578,7 @@
 
 
-pmSubtractionStampList *pmSubtractionStampsSetFromFile(const char *filename, const psImage *subMask,
-                                                       const psRegion *region, int footprint, float spacing,
-                                                       pmSubtractionMode mode)
+pmSubtractionStampList *pmSubtractionStampsSetFromFile(const char *filename, const psImage *image,
+                                                       const psImage *subMask, const psRegion *region,
+                                                       int footprint, float spacing, pmSubtractionMode mode)
 {
     PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
@@ -583,5 +598,5 @@
     psBinaryOp(y, y, "-", psScalarAlloc(1.0, PS_TYPE_F32));
 
-    pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, flux, NULL, subMask, region, footprint,
+    pmSubtractionStampList *stamps = pmSubtractionStampsSet(x, y, flux, image, subMask, region, footprint,
                                                             spacing, mode);
     psFree(data);
