Index: trunk/psphot/src/psphotSkyReplace.c
===================================================================
--- trunk/psphot/src/psphotSkyReplace.c	(revision 6727)
+++ trunk/psphot/src/psphotSkyReplace.c	(revision 6851)
@@ -5,31 +5,25 @@
 bool psphotSkyReplace (pmConfig *config, pmFPAview *view) {
 
-    bool status;
+    // find the currently selected readout
+    pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT");
+    if (readout == NULL) psAbort ("psphot", "input not defined");
 
-    // find the currently selected readout
-    //  psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, "PSPHOT");
-    pmFPAfile *input   = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
-    pmReadout *readout = pmFPAviewThisReadout (view, input->fpa);
+    // select background pixels, from output background file, or create
+    pmReadout *background = pmFPAfileThisReadout (config->files, view, "PSPHOT.BACKGND");
+    if (background == NULL) psAbort ("psphot", "background not defined");
 
     // select the corresponding images
-    psImage *image = readout->image;
-    psImage *mask  = readout->mask;
-
-    // select background pixels, from output background file, or create
-    psImage *background = pmFPAfileReadoutImage (config->files, view, "PSPHOT.BACKGND", 0, 0, PS_TYPE_F32);
-    if (background == NULL) {
-	return false;
-    }
+    psF32 **image = readout->image->data.F32;
+    psU8  **mask  = readout->mask->data.U8;
+    psF32 **back  = background->image->data.F32;
 
     // replace the background model
-    for (int j = 0; j < image->numRows; j++) {
-	for (int i = 0; i < image->numCols; i++) {
-	    if (!mask->data.U8[j][i]) {
-		image->data.F32[j][i] += background->data.F32[j][i];
+    for (int j = 0; j < readout->image->numRows; j++) {
+	for (int i = 0; i < readout->image->numCols; i++) {
+	    if (!mask[j][i]) {
+		image[j][i] += back[j][i];
 	    }
 	}
     }
-    
-    psFree (background);
     return true;
 }
