Index: branches/pap/ppSub/src/ppSubLoop.c
===================================================================
--- branches/pap/ppSub/src/ppSubLoop.c	(revision 23711)
+++ branches/pap/ppSub/src/ppSubLoop.c	(revision 23719)
@@ -17,5 +17,4 @@
 #include <pslib.h>
 #include <psmodules.h>
-#include <ppStats.h>
 
 #include "ppSub.h"
@@ -70,15 +69,15 @@
     }
 
-    if (!ppSubDefineOutput("PPSUB.OUTPUT", config, data, view)) {
+    if (!ppSubDefineOutput("PPSUB.OUTPUT", config)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to define output.");
         return false;
     }
 
-    if (!data->quality && !ppSubMakePSF("PPSUB.OUTPUT", "PPSUB.INVERSE", config, data, view)) {
+    if (!data->quality && !ppSubMakePSF(config, data)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to generate PSF.");
         return false;
     }
 
-    if (!ppSubReadoutSubtract("PPSUB.OUTPUT", config, view)) {
+    if (!ppSubReadoutSubtract(config)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to subtract images.");
         return false;
@@ -86,5 +85,5 @@
 
     // Close convolved files
-    if (!ppSubFilesIterateUp(config, PPSUB_FILES_CONV)) {
+    if (!ppSubFilesIterateUp(config, PPSUB_FILES_PSF | PPSUB_FILES_CONV)) {
         psError(PPSUB_ERR_IO, false, "Unable to close input files.");
         return false;
@@ -92,21 +91,31 @@
 
     // Higher order background subtraction using psphot
-    if (!ppSubBackground(config, view)) {
+    if (!ppSubBackground(config)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to subtract background.");
         return false;
     }
 
-    if (!data->quality && ppSubReadoutPhotometry("PPSUB.OUTPUT", PPSUB_FILES_PHOT_SUB, config, data, view)) {
+    if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_SUB)) {
+        psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
+        return false;
+    }
+
+    if (!data->quality && !ppSubReadoutPhotometry("PPSUB.OUTPUT", config, data)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
         return false;
     }
 
+    if (!ppSubFilesIterateUp(config, PPSUB_FILES_PHOT_SUB)) {
+        psError(PPSUB_ERR_IO, false, "Unable to set up photometry files.");
+        return false;
+    }
+
     // Perform statistics on the cell
-    if (!ppSubReadoutStats(config, data, view)) {
+    if (!ppSubReadoutStats(config, data)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to collect statistics");
         return false;
     }
 
-    if (!ppSubReadoutJpeg("PPSUB.OUTPUT", config, data, view)) {
+    if (!ppSubReadoutJpeg(config)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to update.");
         return false;
@@ -120,10 +129,10 @@
         }
 
-        if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config, data, view)) {
+        if (data->inverse && !ppSubDefineOutput("PPSUB.INVERSE", config)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to define inverse.");
             return false;
         }
 
-        if (!ppSubReadoutInverse("PPSUB.INVERSE", "PPSUB.OUTPUT", config, view)) {
+        if (!ppSubReadoutInverse(config)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to invert images.");
             return false;
@@ -136,6 +145,10 @@
         }
 
-        if (!data->quality && data->!ppSubReadoutPhotometry("PPSUB.INVERSE", PPSUB_FILES_PHOT_INV,
-                                                            config, data, view)) {
+        if (!ppSubFilesIterateDown(config, PPSUB_FILES_PHOT_INV)) {
+            psError(PPSUB_ERR_IO, false, "Unable to set up inverse files.");
+            return false;
+        }
+
+        if (!data->quality && !ppSubReadoutPhotometry("PPSUB.INVERSE", config, data)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry.");
             return false;
@@ -143,5 +156,5 @@
 
         // Close inverse subtraction files
-        if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV)) {
+        if (!ppSubFilesIterateUp(config, PPSUB_FILES_INV | PPSUB_FILES_PHOT_INV)) {
             psError(PPSUB_ERR_IO, false, "Unable to close subtraction files.");
             return false;
@@ -155,7 +168,5 @@
     }
 
-    psFree(view);
-
-    psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "-dumpconfig");
+    psString dump_file = psMetadataLookupStr(NULL, config->arguments, "-dumpconfig");
     if (dump_file) {
         pmFPAfile *input = psMetadataLookupPtr(NULL, config->files, "PPSUB.INPUT"); // Input file
@@ -164,6 +175,3 @@
 
     return true;
-
-ERROR:
-    return false;
 }
