Index: trunk/ppBackground/src/ppBackgroundLoop.c
===================================================================
--- trunk/ppBackground/src/ppBackgroundLoop.c	(revision 28296)
+++ trunk/ppBackground/src/ppBackgroundLoop.c	(revision 28300)
@@ -86,4 +86,6 @@
                     readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
                     psImageInit(readout->image, 0.0);
+                    readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
+                    psImageInit(readout->mask, 0);
 
                     if (!pmPatternRowApply(readout, maskBad) || !pmPatternCellApply(readout, maskBad)) {
@@ -116,20 +118,22 @@
             }
 
-            pmChip *mosaic = pmFPAviewThisChip(view, patternMosaic); // Chip for mosaicked pattern
-            if (!mosaic->hdu && !mosaic->parent->hdu) {
-                pmFPAAddSourceFromView(patternMosaic, view, file->format);
+            if (data->patternName) {
+                pmChip *patternChip = pmFPAviewThisChip(view, patternFile->fpa); // Chip for pattern
+                pmChip *mosaic = pmFPAviewThisChip(view, patternMosaic); // Chip for mosaicked pattern
+                if (!mosaic->hdu && !mosaic->parent->hdu) {
+                    pmFPAAddSourceFromView(patternMosaic, view, file->format);
+                }
+                if (!pmChipMosaic(mosaic, patternChip, true, maskBad)) {
+                    psError(psErrorCodeLast(), false, "Unable to mosaic pattern correction");
+                    return false;
+                }
+                pmFPAfileActivate(config->files, true, NULL);
+            //            pmFPAfileActivate(config->files, false, "PPBACKGROUND.PATTERN");
             }
-            if (!pmChipMosaic(mosaic, chip, true, maskBad)) {
-                psError(psErrorCodeLast(), false, "Unable to mosaic pattern correction");
-                return false;
-            }
-            pmFPAfileActivate(config->files, true, NULL);
-            //            pmFPAfileActivate(config->files, false, "PPBACKGROUND.PATTERN");
         }
 
-        pmChip *outChip = pmFPAfileThisChip(config->files, view, "PPBACKGROUND.OUTPUT"); // Chip for output
         pmChip *patternChip = patternFile ? pmFPAviewThisChip(view, patternMosaic) : NULL; // Chip with pattern
         pmChip *bgChip = bgFile ? pmFPAviewThisChip(view, bgFile->fpa) : NULL; // Chip with background model
-        if (!ppBackgroundRestore(outChip, chip, bgChip, patternChip, view, config)) {
+        if (!ppBackgroundRestore(chip, bgChip, patternChip, view, config)) {
             psError(psErrorCodeLast(), false, "Unable to replace background");
             return false;
