Index: /trunk/ppbgrestore/src/ppbgrestoreCleanup.c
===================================================================
--- /trunk/ppbgrestore/src/ppbgrestoreCleanup.c	(revision 26663)
+++ /trunk/ppbgrestore/src/ppbgrestoreCleanup.c	(revision 26664)
@@ -22,5 +22,5 @@
     // fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "ppImage");
 
-    fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "ppbgrestore");
+//    fprintf(stderr, "Found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "ppbgrestore");
 
 }
Index: /trunk/ppbgrestore/src/ppbgrestoreLoop.c
===================================================================
--- /trunk/ppbgrestore/src/ppbgrestoreLoop.c	(revision 26663)
+++ /trunk/ppbgrestore/src/ppbgrestoreLoop.c	(revision 26664)
@@ -104,7 +104,17 @@
             return false;
         }
-        pmReadout *backgroundRO = pmFPAviewThisReadout(&roView, background->fpa);
-//        pmReadout *backgroundRO = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32);
+        pmReadout *backgroundRO;
+#define USE_CELL
+#ifdef USE_CELL
+        pmCell *backgroundCell = pmFPAviewThisCell(&roView, background->fpa);
+        backgroundRO = pmReadoutAlloc(backgroundCell);
+#else
+        backgroundRO = pmFPAviewThisReadout(&roView, background->fpa);
+//        backgroundRO = pmFPAfileDefineInternal (config->files, "PSPHOT.BACKGND", image->numCols, image->numRows, PS_TYPE_F32);
+#endif
         backgroundRO->image = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32);
+	backgroundRO->data_exists = true;
+	backgroundRO->parent->data_exists = true;
+	backgroundRO->parent->parent->data_exists = true;
 
         // linear interpolation to full-scale
@@ -120,4 +130,5 @@
         int numCols = image->numCols, numRows = image->numRows; // Size of image
         long nancount = 0;
+        long naninputs = 0;
         long finitecount = 0;
         for (int y = 0; y < numRows; y++) {
@@ -140,7 +151,12 @@
                 } else if (isfinite(imageval)) {
                     // XXX: TODO:following ppImage we should not modify pixels that are masked.
-                    image->data.F32[y][x] += bgvalue;
-                }
+                    image->data.F32[y][x] = imageval + bgvalue;
+                } else {
+		    naninputs++;
+		}
             }
+        }
+        if (naninputs) {
+            printf("%ld infinite pixels found in input image\n", naninputs);
         }
         if (nancount) {
Index: /trunk/ppbgrestore/src/ppbgrestoreParseCamera.c
===================================================================
--- /trunk/ppbgrestore/src/ppbgrestoreParseCamera.c	(revision 26663)
+++ /trunk/ppbgrestore/src/ppbgrestoreParseCamera.c	(revision 26664)
@@ -27,5 +27,6 @@
         return NULL;
     }
-    pmFPAfile *outBG = pmFPAfileDefineOutput(config, input->fpa, "PPBGRESTORE.BACKGROUND");
+    // pmFPAfile *outBG = pmFPAfileDefineOutput(config, NULL, "PPBGRESTORE.BACKGROUND");
+    pmFPAfile *outBG = pmFPAfileDefineFromFPA(config, input->fpa, 1, 1, "PPBGRESTORE.BACKGROUND");
     if (!outBG) {
         psError(PS_ERR_IO, false, _("Unable to generate bacgkround file from PPBGRESTORE.BACKGROUND"));
