Index: /branches/pap_branch_080207/ppStack/src/ppStackMatch.c
===================================================================
--- /branches/pap_branch_080207/ppStack/src/ppStackMatch.c	(revision 16372)
+++ /branches/pap_branch_080207/ppStack/src/ppStackMatch.c	(revision 16373)
@@ -11,6 +11,5 @@
 //#define TESTING
 
-bool ppStackMatch(pmReadout *output, const pmReadout *input, const pmReadout *sourcesRO,
-                  const pmPSF *psf, const pmConfig *config)
+bool ppStackMatch(pmReadout *readout, const pmReadout *sourcesRO, const pmPSF *psf, const pmConfig *config)
 {
     // Look up appropriate values from the ppSub recipe
@@ -68,5 +67,5 @@
     pmReadout *fake = pmReadoutAlloc(NULL); // Fake readout with target PSF
 
-    if (!pmReadoutFakeFromSources(fake, input->image->numCols, input->image->numRows, sources, NULL, NULL,
+    if (!pmReadoutFakeFromSources(fake, readout->image->numCols, readout->image->numRows, sources, NULL, NULL,
                                   psf, powf(10.0, -0.4 * maxMag), 0, false)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to generate fake image with target PSF.");
@@ -85,5 +84,6 @@
 
     // Do the image matching
-    if (!pmSubtractionMatch(output, NULL, input, fake, footprint, regionSize, spacing, threshold,
+    pmReadout *output = pmReadoutAlloc(NULL); // Output readout, for holding results temporarily
+    if (!pmSubtractionMatch(output, NULL, readout, fake, footprint, regionSize, spacing, threshold,
                             sources, stampsName, type, size, order, widths, orders, inner, ringsOrder,
                             binning, optimum, optWidths, optOrder, optThresh, iter, rej, maskBad,
@@ -92,4 +92,5 @@
         psFree(fake);
         psFree(optWidths);
+        psFree(output);
         return false;
     }
@@ -97,4 +98,13 @@
     psFree(optWidths);
 
+    // Replace original images with convolved
+    psFree(readout->image);
+    psFree(readout->mask);
+    psFree(readout->weight);
+    readout->image  = psMemIncrRefCounter(output->image);
+    readout->mask   = psMemIncrRefCounter(output->mask);
+    readout->weight = psMemIncrRefCounter(output->weight);
+    psFree(output);
+
     return true;
 }
