Index: trunk/ppStack/src/ppStackCombineFinal.c
===================================================================
--- trunk/ppStack/src/ppStackCombineFinal.c	(revision 27319)
+++ trunk/ppStack/src/ppStackCombineFinal.c	(revision 27400)
@@ -14,6 +14,6 @@
 //#define TESTING                         // Enable test output
 
-bool ppStackCombineFinal(pmReadout *target, ppStackThreadData *stack, psArray *covariances,
-                         ppStackOptions *options, pmConfig *config, bool safe, bool normalise, bool grow)
+bool ppStackCombineFinal(ppStackThreadData *stack, psArray *covariances, ppStackOptions *options,
+                         pmConfig *config, bool safe, bool normalise, bool grow)
 {
     psAssert(stack, "Require stack");
@@ -21,5 +21,7 @@
     psAssert(config, "Require configuration");
 
-    int numCols = target->image->numCols, numRows = target->image->numRows; // Size of image
+    pmReadout *outRO = options->outRO;                                      // Output readout
+    pmReadout *expRO = options->expRO;                                      // Exposure readout
+    int numCols = outRO->image->numCols, numRows = outRO->image->numRows; // Size of image
 
     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
@@ -43,6 +45,9 @@
     }
 
-    if (!target->mask) {
-        target->mask = psImageAlloc(target->image->numCols, target->image->numRows, PS_TYPE_IMAGE_MASK);
+    if (!outRO->mask) {
+        outRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
+    }
+    if (!expRO->mask) {
+        expRO->mask = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     }
 
@@ -62,7 +67,6 @@
         }
 
-        // call: ppStackReadoutFinal(config, target, readouts, rejected)
+        // call: ppStackReadoutFinal(config, outRO, readouts, rejected)
         psThreadJob *job = psThreadJobAlloc("PPSTACK_FINAL_COMBINE"); // Job to start
-        psArrayAdd(job->args, 1, target);
         psArrayAdd(job->args, 1, thread);
         psArrayAdd(job->args, 1, reject);
@@ -105,11 +109,11 @@
         }
         if (sumWeights > 0.0) {
-            target->covariance = psImageCovarianceSum(covariances);
-            psBinaryOp(target->covariance->image, target->covariance->image, "/",
+            outRO->covariance = psImageCovarianceSum(covariances);
+            psBinaryOp(outRO->covariance->image, outRO->covariance->image, "/",
                        psScalarAlloc(sumWeights, PS_TYPE_F32));
-            psImageCovarianceTransfer(target->variance, target->covariance);
+            psImageCovarianceTransfer(outRO->variance, outRO->covariance);
         }
     } else {
-        target->covariance = psImageCovarianceNone();
+        outRO->covariance = psImageCovarianceNone();
     }
 
@@ -127,6 +131,6 @@
             wcsDone = true;
             pmHDU *inHDU = pmHDUFromCell(inRO->parent); // Template HDU
-            pmHDU *outHDU = pmHDUFromCell(target->parent); // Output HDU
-            pmChip *outChip = target->parent->parent; // Output chip
+            pmHDU *outHDU = pmHDUFromCell(outRO->parent); // Output HDU
+            pmChip *outChip = outRO->parent->parent; // Output chip
             pmFPA *outFPA = outChip->parent; // Output FPA
             if (!outHDU || !inHDU) {
@@ -151,6 +155,26 @@
     }
 
+    // Set exposure time correctly
+    {
+        float exptime = 0.0;            // Summed exposure time
+        for (int i = 0; i < options->num; i++) {
+            if (options->inputMask) {
+                continue;
+            }
+            exptime += options->exposures->data.F32[i];
+        }
+
+        {
+            psMetadataItem *item = psMetadataLookup(outRO->parent->concepts, "CELL.EXPOSURE");
+            item->data.F32 = exptime;
+        }
+        {
+            psMetadataItem *item = psMetadataLookup(outRO->parent->parent->parent->concepts, "FPA.EXPOSURE");
+            item->data.F32 = exptime;
+        }
+    }
+
     // Put version information into the header
-    pmHDU *hdu = pmHDUFromCell(target->parent);
+    pmHDU *hdu = pmHDUFromCell(outRO->parent);
     if (!hdu) {
         psError(PPSTACK_ERR_PROG, false, "Unable to find HDU for output.");
@@ -168,12 +192,12 @@
     psStringAppend(&name, "combined_image_final_%d.fits", pass);
     pass++;
-    ppStackWriteImage(name, NULL, target->image, config);
+    ppStackWriteImage(name, NULL, outRO->image, config);
     psStringSubstitute(&name, "mask", "image");
-    ppStackWriteImage(name, NULL, target->mask, config);
+    ppStackWriteImage(name, NULL, outRO->mask, config);
     psStringSubstitute(&name, "variance", "mask");
-    ppStackWriteImage(name, NULL, target->variance, config);
+    ppStackWriteImage(name, NULL, outRO->variance, config);
     psFree(name);
 
-    pmStackVisualPlotTestImage(target->image, "combined_image_final.fits");
+    pmStackVisualPlotTestImage(outRO->image, "combined_image_final.fits");
 #endif
 
