Index: branches/tap_branches/ppStack/src/ppStackPhotometry.c
===================================================================
--- branches/tap_branches/ppStack/src/ppStackPhotometry.c	(revision 25900)
+++ branches/tap_branches/ppStack/src/ppStackPhotometry.c	(revision 27838)
@@ -19,6 +19,5 @@
     psAssert(recipe, "We've thrown an error on this before.");
 
-    bool mdok;                          // Status of MD lookup
-    if (!psMetadataLookupBool(&mdok, recipe, "PHOTOMETRY")) {
+    if (!options->photometry) {
         // Nothing to do
         return true;
@@ -27,8 +26,8 @@
     psTimerStart("PPSTACK_PHOT");
 
-    ppStackFileActivation(config, PPSTACK_FILES_COMBINE, false);
+    pmFPAfileActivate(config->files, false, NULL);
     ppStackFileActivation(config, PPSTACK_FILES_PHOT, true);
     pmFPAview *photView = ppStackFilesIterateDown(config); // View to readout
-    ppStackFileActivation(config, PPSTACK_FILES_COMBINE, true);
+    ppStackFileActivation(config, PPSTACK_FILES_STACK, true);
 
     pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT"); // File for photometry
@@ -60,12 +59,12 @@
                            "Bits to use for mark", markValue);
 
-    pmCell *sourcesCell = pmFPAfileThisCell(config->files, photView, "PPSTACK.OUTPUT");
-    psArray *inSources = psMetadataLookupPtr(NULL, sourcesCell->analysis, "PSPHOT.SOURCES");
+    psArray *inSources = options->sources;
     if (!inSources) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to find input sources");
+        psError(PPSTACK_ERR_PROG, false, "Unable to find input sources");
         psFree(photView);
         return false;
     }
 
+    pmModelClassSetLimits(PM_MODEL_LIMITS_LAX);
     if (!psphotReadoutKnownSources(config, photView, inSources)) {
         // This is likely a data quality issue
@@ -73,7 +72,6 @@
         psErrorStackPrint(stderr, "Unable to perform photometry on image");
         psWarning("Unable to perform photometry on image --- suspect bad data quality.");
-        if (options->stats && psMetadataLookupS32(NULL, options->stats, "QUALITY") == 0) {
-            psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE,
-                             "Unable to perform photometry on image", psErrorCodeLast());
+        if (options->quality == 0) {
+            options->quality = psErrorCodeLast();
         }
         psErrorClear();
@@ -84,5 +82,5 @@
         !pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV") ||
         !pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND")) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to drop PSPHOT internal files.");
+        psError(PPSTACK_ERR_PROG, false, "Unable to drop PSPHOT internal files.");
         return false;
     }
@@ -92,10 +90,13 @@
     if (options->stats) {
         pmReadout *photRO = pmFPAviewThisReadout(photView, photFile->fpa); // Readout with the sources
-        psArray *sources = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.SOURCES"); // Sources
-        psMetadataAddS32(options->stats, PS_LIST_TAIL, "NUM_SOURCES", 0,
-                         "Number of sources detected", sources ? sources->n : 0);
-        psMetadataAddF32(options->stats, PS_LIST_TAIL, "TIME_PHOT", 0,
-                         "Time to do photometry", psTimerMark("PPSTACK_PHOT"));
+        pmDetections *detections = psMetadataLookupPtr(NULL, photRO->analysis, "PSPHOT.DETECTIONS"); // detections
+        if (detections && detections->allSources) {
+            psMetadataAddS32(options->stats, PS_LIST_TAIL, "NUM_SOURCES", 0, "Number of sources detected", detections->allSources->n);
+        } else {
+            psMetadataAddS32(options->stats, PS_LIST_TAIL, "NUM_SOURCES", 0, "Number of sources detected", 0);
+        }
+        psMetadataAddF32(options->stats, PS_LIST_TAIL, "TIME_PHOT", 0, "Time to do photometry", psTimerMark("PPSTACK_PHOT"));
     }
+
     psFree(photView);
 
