Index: /trunk/ppBackground/src/ppBackground.h
===================================================================
--- /trunk/ppBackground/src/ppBackground.h	(revision 28299)
+++ /trunk/ppBackground/src/ppBackground.h	(revision 28300)
@@ -39,6 +39,5 @@
 /// Restore the background to an image
 bool ppBackgroundRestore(
-    pmChip *out,                        // Output chip
-    const pmChip *chip,                 // Input chip
+    pmChip *chip,                       // Chip to correct
     const pmChip *background,           // Chip with background model
     const pmChip *pattern,              // Chip with pattern
Index: /trunk/ppBackground/src/ppBackgroundLoop.c
===================================================================
--- /trunk/ppBackground/src/ppBackgroundLoop.c	(revision 28299)
+++ /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;
Index: /trunk/ppBackground/src/ppBackgroundRestore.c
===================================================================
--- /trunk/ppBackground/src/ppBackgroundRestore.c	(revision 28299)
+++ /trunk/ppBackground/src/ppBackgroundRestore.c	(revision 28300)
@@ -6,8 +6,7 @@
 #include "ppBackground.h"
 
-bool ppBackgroundRestore(pmChip *out, const pmChip *chip, const pmChip *background, const pmChip *pattern,
+bool ppBackgroundRestore(pmChip *chip, const pmChip *background, const pmChip *pattern,
                          const pmFPAview *oldView, pmConfig *config)
 {
-    PS_ASSERT_PTR_NON_NULL(out, false);
     PS_ASSERT_PTR_NON_NULL(chip, false);
     PS_ASSERT_PTR_NON_NULL(oldView, false);
@@ -18,25 +17,15 @@
     view->readout = 0;
 
-    pmReadout *inRO = pmFPAviewThisReadout(view, chip->parent);
-    if (!inRO || !inRO->data_exists) {
+    pmReadout *ro = pmFPAviewThisReadout(view, chip->parent);
+    if (!ro || !ro->data_exists) {
         psError(PPBACKGROUND_ERR_CONFIG, true, "Readout has no data");
         return false;
     }
-    const psImage *inImage = inRO->image, *inMask = inRO->mask;   // Input image
-    int numCols = inImage->numCols, numRows = inImage->numRows; // Size of image
-
-    pmReadout *outRO = pmFPAviewThisReadout(view, out->parent);
-    if (!outRO) {
-        pmCell *outCell = pmFPAviewThisCell(view, out->parent);
-        outRO = pmReadoutAlloc(outCell);
-        psFree(outRO);                  // Drop reference
-    }
-    outRO->image = psImageCopy(outRO->image, inImage, PS_TYPE_F32);
-    outRO->mask = psImageCopy(outRO->mask, inMask, PS_TYPE_IMAGE_MASK);
-    psImage *outImage = outRO->image, *outMask = outRO->mask; // Output image
+    const psImage *image = ro->image, *mask = ro->mask;   // Input image
+    int numCols = image->numCols, numRows = image->numRows; // Size of image
 
     if (background) {
         pmReadout *bgRO = pmFPAviewThisReadout(view, background->parent); // Readout with background
-        psImageBinning *binning = psphotBackgroundBinning(outImage, config);
+        psImageBinning *binning = psphotBackgroundBinning(image, config);
         if (!binning) {
             psError(psErrorCodeLast(), false, "Unable to find background binning");
@@ -60,5 +49,5 @@
         for (int y = 0; y < numRows; y++) {
             for (int x = 0; x < numCols; x++) {
-                outImage->data.F32[y][x] += bgImage->data.F32[y][x];
+                image->data.F32[y][x] += bgImage->data.F32[y][x];
             }
         }
@@ -72,13 +61,13 @@
         for (int y = 0; y < numRows; y++) {
             for (int x = 0; x < numCols; x++) {
-                outImage->data.F32[y][x] = patternImage->data.F32[y][x];
-                outMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= patternMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x];
+                image->data.F32[y][x] -= patternImage->data.F32[y][x];
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= patternMask->data.PS_TYPE_IMAGE_MASK_DATA[y][x];
             }
         }
     }
 
-    outRO->data_exists = true;
-    outRO->parent->data_exists = true;
-    outRO->parent->parent->data_exists = true;
+    ro->data_exists = true;
+    ro->parent->data_exists = true;
+    ro->parent->parent->data_exists = true;
 
     return true;
