Index: /branches/eam_branches/gDiff.20200202/src/gDiffCamera.c
===================================================================
--- /branches/eam_branches/gDiff.20200202/src/gDiffCamera.c	(revision 41413)
+++ /branches/eam_branches/gDiff.20200202/src/gDiffCamera.c	(revision 41414)
@@ -475,5 +475,5 @@
     if (data->forcedPhot1) {
 	// this pmFPAfile is used to carry sources detected in the positive image #1
-	pmFPAfile *posSources1 = defineOutputFile(config, input, true, "GDIFF.POS1.SOURCES", PM_FPA_FILE_CMF);
+	pmFPAfile *posSources1 = defineOutputFile(config, output, true, "GDIFF.POS1.SOURCES", PM_FPA_FILE_CMF);
 	if (!posSources1) {
 	    psError(psErrorCodeLast(), false, "Unable to set up forced source file.");
@@ -483,5 +483,5 @@
 
 	// this pmFPAfile is used to carry sources detected in the diff image @ the positions from positive image #1
-	pmFPAfile *frcSources1 = defineOutputFile(config, input, true, "GDIFF.FORCED1.SOURCES", PM_FPA_FILE_CMF);
+	pmFPAfile *frcSources1 = defineOutputFile(config, output, true, "GDIFF.FORCED1.SOURCES", PM_FPA_FILE_CMF);
 	if (!frcSources1) {
 	    psError(psErrorCodeLast(), false, "Unable to set up forced source file.");
Index: /branches/eam_branches/gDiff.20200202/src/gDiffDefineOutput.c
===================================================================
--- /branches/eam_branches/gDiff.20200202/src/gDiffDefineOutput.c	(revision 41413)
+++ /branches/eam_branches/gDiff.20200202/src/gDiffDefineOutput.c	(revision 41414)
@@ -27,4 +27,7 @@
 
     // The output readout may already be present if we read in the convolution kernel
+    // NOTE: pmReadoutAlloc returns a reference and saves one on the supplied cell.  The
+    // psMemIncrRefCounter below is needed in the first block so we can free the
+    // reference.  (we should code this to drop the returned reference in the second block
     pmReadout *outRO = NULL;            // Output readout
     if (outCell->readouts && outCell->readouts->n > 0 && outCell->readouts->data[0]) {
Index: /branches/eam_branches/gDiff.20200202/src/gDiffExtras.c
===================================================================
--- /branches/eam_branches/gDiff.20200202/src/gDiffExtras.c	(revision 41413)
+++ /branches/eam_branches/gDiff.20200202/src/gDiffExtras.c	(revision 41414)
@@ -21,6 +21,7 @@
     if (!targetRO) {
 	pmCell *targetCell = pmFPAviewThisCell(view, target->fpa);
-	targetRO = pmReadoutAlloc(targetCell);
+	targetRO = pmReadoutAlloc(targetCell); // returns a reference and adds one to the cell
 	psAssert(targetRO, "programming error: could not make target readout");
+	psFree (targetRO); // free the reference
     }
 
@@ -55,5 +56,7 @@
     if (hdu) {
 	psMetadata *header = psMetadataLookupMetadata(NULL, targetRO->analysis, "PSPHOT.HEADER"); // Header
-	hdu->header = psMetadataCopy(hdu->header, header);
+	if (header) {
+	  hdu->header = psMetadataCopy(hdu->header, header);
+	}
     }
 
Index: /branches/eam_branches/gDiff.20200202/src/gDiffFiles.c
===================================================================
--- /branches/eam_branches/gDiff.20200202/src/gDiffFiles.c	(revision 41413)
+++ /branches/eam_branches/gDiff.20200202/src/gDiffFiles.c	(revision 41414)
@@ -31,5 +31,7 @@
 
 // Subtraction photometry
-static const char *subPhotFiles[] = { "GDIFF.OUTPUT.SOURCES", NULL };
+static const char *subPhotFiles[] = { "GDIFF.OUTPUT.SOURCES",
+				      "GDIFF.POS1.SOURCES", "GDIFF.FORCED1.SOURCES",
+				      "GDIFF.POS2.SOURCES", "GDIFF.FORCED2.SOURCES", NULL };
 
 // Inverse subtraction files
Index: /branches/eam_branches/gDiff.20200202/src/gDiffLoop.c
===================================================================
--- /branches/eam_branches/gDiff.20200202/src/gDiffLoop.c	(revision 41413)
+++ /branches/eam_branches/gDiff.20200202/src/gDiffLoop.c	(revision 41414)
@@ -26,6 +26,4 @@
     psAssert(config, "Require configuration.");
 
-    HDUCHECK ("0a: start gDiffLoop");
-
     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, GDIFF_RECIPE); // Recipe for ppSim
     psAssert(recipe, "We checked this earlier, so it should be here.");
@@ -49,6 +47,4 @@
     psTimerStart("GDIFF_MATCH");
 
-    HDUCHECK ("0b: gDiffSetMasks");
-
     if (!gDiffSetMasks(config)) {
         psError(psErrorCodeLast(), false, "Unable to set masks.");
@@ -56,5 +52,4 @@
     }
 
-    HDUCHECK ("0b.1: gDiffInputDetections");
     if (data->forcedPhot1) {
 	bool foundDetections = false;
@@ -70,5 +65,5 @@
 	}
     }
-    HDUCHECK ("0b.2: gDiffInputDetections");
+
     if (data->forcedPhot2) {
 	// XXX why is this only done for Phot2 and not Phot1 ??
@@ -110,6 +105,4 @@
      **** This is the core of the PSF-matched image subtraction code.   ****/
 
-    HDUCHECK ("1: before gDiffMatchPSFs");
-
     if (!gDiffMatchPSFs(data)) {
 	psError(psErrorCodeLast(), false, "Unable to match PSFs.");
@@ -152,6 +145,4 @@
     }
 
-    HDUCHECK ("2: after gDiffLowThreshold");
-
     // Set up subtraction files
     if (!gDiffFilesIterateDown(config, GDIFF_FILES_SUB)) {
@@ -166,6 +157,4 @@
         goto ESCAPE;
     }
-
-    HDUCHECK ("2a: gDiffMakePSF");
 
     // the functions in this block are not critical for initial testing, so block them out for now
@@ -186,6 +175,4 @@
     }
 
-    HDUCHECK ("3: before gDiffReadoutSubtract");
-
     if (!gDiffReadoutSubtract(config)) {
         psError(psErrorCodeLast(), false, "Unable to subtract images.");
@@ -208,6 +195,4 @@
     }
     
-    HDUCHECK ("4: before gDiffBackground");
-
     // Higher order background subtraction using psphot
     if (!gDiffBackground(config)) {
@@ -218,6 +203,4 @@
     // dumpout(config, "diff.2b.fits");
 
-    HDUCHECK ("5: before gDiffVarianceRescale");
-
     // Perform Variance correction (rescale within a modest range)
     if (!gDiffVarianceRescale(config, data)) {
@@ -240,6 +223,4 @@
     }
 
-    HDUCHECK ("6: before gDiffReadoutPhotometry");
-
     if (!data->quality && !gDiffReadoutPhotometry("GDIFF.OUTPUT", data)) {
         psError(psErrorCodeLast(), false, "Unable to perform photometry.");
@@ -248,6 +229,4 @@
     }
     // dumpout(config, "diff.3.fits");
-
-    HDUCHECK ("7: before gDiffReadoutForcedPhot (1)");
 
     // forced photometry for positive image 1
Index: /branches/eam_branches/gDiff.20200202/src/gDiffMakePSF.c
===================================================================
--- /branches/eam_branches/gDiff.20200202/src/gDiffMakePSF.c	(revision 41413)
+++ /branches/eam_branches/gDiff.20200202/src/gDiffMakePSF.c	(revision 41414)
@@ -17,5 +17,5 @@
     psAssert(config, "Require configuration");
 
-    if (!data->photometry) {
+    if (!data->photometry && !data->forcedPhot1 && !data->forcedPhot2) {
         return true;
     }
