Index: trunk/stac/src/stacCombine.c
===================================================================
--- trunk/stac/src/stacCombine.c	(revision 3673)
+++ trunk/stac/src/stacCombine.c	(revision 5743)
@@ -10,5 +10,5 @@
 float stacCombineMean(psVector *values,	// Values for which to take the mean
 		      psVector *errors,	// Errors in the values
-		      psVector *masks	// Masks for the values, 0 = don't use, 1 = use
+		      psVector *masks	// Masks for the values, 1 = don't use, 0 = use
     )
 {
@@ -149,6 +149,10 @@
 		    }
 		}
-	    
+		
 		float average = stacCombineMean(pixels, deltas, mask); // Combined value
+
+		// We set the value BEFORE the rejection iteration because not all pixels that we reject
+		// here will be rejected in the final cut.
+		(*combined)->data.F32[y][x] = average;
 
 #ifdef TESTING
@@ -188,6 +192,4 @@
 		}
 	    
-		(*combined)->data.F32[y][x] = average;
-
 	    } // Pixels of interest
 
@@ -201,5 +203,5 @@
     sprintf(chiName,"chi2_%d.fits",iteration);
     psFits *chiFile = psFitsAlloc(chiName);
-    if (!psFitsWriteImage(chiFile, NULL, chi2 , 0, NULL)) {
+    if (!psFitsWriteImage(chiFile, NULL, chi2 , 0)) {
 	psErrorStackPrint(stderr, "Unable to write image: %s\n", chiName);
     }
