Index: branches/tap_branches/ppStack/src/ppStackReject.c
===================================================================
--- branches/tap_branches/ppStack/src/ppStackReject.c	(revision 25900)
+++ branches/tap_branches/ppStack/src/ppStackReject.c	(revision 27838)
@@ -10,5 +10,5 @@
 #include "ppStackLoop.h"
 
-//#define TESTING
+// #define TESTING
 
 bool ppStackReject(ppStackOptions *options, pmConfig *config)
@@ -23,5 +23,4 @@
 
     int num = options->num;             // Number of inputs
-    options->rejected = psArrayAlloc(num);
 
     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
@@ -32,5 +31,4 @@
 
     float threshold = psMetadataLookupF32(NULL, recipe, "THRESHOLD.MASK"); // Threshold for mask deconvolution
-    float poorFrac = psMetadataLookupF32(NULL, recipe, "POOR.FRACTION"); // Fraction for "poor"
     float imageRej = psMetadataLookupF32(NULL, recipe, "IMAGE.REJ"); // Maximum fraction of image to reject
                                                                      // before rejecting entire image
@@ -53,4 +51,5 @@
         psThreadJob *job = psThreadJobAlloc("PPSTACK_INSPECT"); // Job to start
         psArrayAdd(job->args, 1, options->inspect);
+        psArrayAdd(job->args, 1, options->rejected);
         PS_ARRAY_ADD_SCALAR(job->args, i, PS_TYPE_S32);
         if (!psThreadJobAddPending(job)) {
@@ -61,5 +60,5 @@
     }
     if (!psThreadPoolWait(true)) {
-        psError(PS_ERR_UNKNOWN, false, "Unable to concatenate inspection lists.");
+        psError(psErrorCodeLast(), false, "Unable to concatenate inspection lists.");
         return false;
     }
@@ -92,15 +91,11 @@
 #endif
 
-        psPixels *reject = pmStackReject(options->inspect->data[i], options->numCols, options->numRows,
-                                         threshold, poorFrac, stride, options->regions->data[i],
-                                         options->kernels->data[i]); // Rejected pixels
-
 #ifdef TESTING
         {
-            psImage *mask = psPixelsToMask(NULL, reject,
+            psImage *mask = psPixelsToMask(NULL, options->rejected->data[i],
                                            psRegionSet(0, options->numCols - 1, 0, options->numRows - 1),
                                            0xff); // Mask image
             psString name = NULL;           // Name of image
-            psStringAppend(&name, "reject_%03d.fits", i);
+            psStringAppend(&name, "pre_reject_%03d.fits", i);
             pmStackVisualPlotTestImage(mask, name);
             psFits *fits = psFitsOpen(name, "w");
@@ -111,4 +106,8 @@
         }
 #endif
+
+        psPixels *reject = pmStackReject(options->inspect->data[i], options->numCols, options->numRows,
+                                         threshold, stride, options->regions->data[i],
+                                         options->kernels->data[i]); // Rejected pixels
 
         psFree(options->inspect->data[i]);
@@ -127,13 +126,29 @@
                           "exceeds limit (%.3f)", i, frac, imageRej);
                 psFree(reject);
-                // reject == NULL means reject image completely
                 reject = NULL;
                 options->inputMask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= PPSTACK_MASK_BAD;
                 numRejected++;
+            } else {
+                // Add to list of pixels already rejected
+                reject = psPixelsConcatenate(reject, options->rejected->data[i]);
+                options->rejected->data[i] = psPixelsDuplicates(options->rejected->data[i], reject);
             }
         }
 
-        // Images without a list of rejected pixels (the list may be empty) are rejected completely
-        options->rejected->data[i] = reject;
+#ifdef TESTING
+        {
+            psImage *mask = psPixelsToMask(NULL, options->rejected->data[i],
+                                           psRegionSet(0, options->numCols - 1, 0, options->numRows - 1),
+                                           0xff); // Mask image
+            psString name = NULL;           // Name of image
+            psStringAppend(&name, "reject_%03d.fits", i);
+            pmStackVisualPlotTestImage(mask, name);
+            psFits *fits = psFitsOpen(name, "w");
+            psFree(name);
+            psFitsWriteImage(fits, NULL, mask, 0, NULL);
+            psFree(mask);
+            psFitsClose(fits);
+        }
+#endif
 
         if (options->stats) {
@@ -143,4 +158,6 @@
                              "Number of pixels rejected", reject ? reject->n : 0);
         }
+
+        psFree(reject);
         psLogMsg("ppStack", PS_LOG_INFO, "Time to perform rejection on image %d: %f sec", i,
                  psTimerClear("PPSTACK_REJECT"));
@@ -148,9 +165,7 @@
 
     psFree(options->inspect); options->inspect = NULL;
-    psFree(options->kernels); options->kernels = NULL;
-    psFree(options->regions); options->regions = NULL;
 
-    if (numRejected >= num - 1) {
-        psError(PS_ERR_UNKNOWN, true, "All inputs completely rejected; unable to proceed.");
+    if (numRejected >= num) {
+        psError(PPSTACK_ERR_REJECTED, true, "All inputs completely rejected; unable to proceed.");
         return false;
     }
