Index: trunk/stac/src/stacCombine.c
===================================================================
--- trunk/stac/src/stacCombine.c	(revision 2670)
+++ trunk/stac/src/stacCombine.c	(revision 2764)
@@ -106,9 +106,9 @@
 	}
 	for (int i = 0; i < nImages; i++) {
-	    (*rejected)->data[i] = psImageAlloc(numCols, numRows, PS_TYPE_F32); // Create rejection mask
+	    (*rejected)->data[i] = psImageAlloc(numCols, numRows, PS_TYPE_U8); // Create rejection mask
 	    // Zero out the mask
 	    for (int r = 0; r < numRows; r++) {
 		for (int c = 0; c < numCols; c++) {
-		    ((psImage*)((*rejected)->data[i]))->data.F32[r][c] = 0.0;
+		    ((psImage*)((*rejected)->data[i]))->data.U8[r][c] = 0;
 		}
 	    }
@@ -154,7 +154,8 @@
 	    
 	    // Rejection iterations
-	    for (int rejNum = 0; rejNum < nReject; rejNum++) {
-		float max = 0.0;
-		int maxIndex = -1;
+	    bool keepGoing = true;	// Keep going with rejection?
+	    for (int rejNum = 0; (rejNum < nReject) && keepGoing; rejNum++) {
+		float max = 0.0;	// Maximum deviation
+		int maxIndex = -1;	// Index of the maximum deviation
 		for (int i = 0; i < nImages; i++) {
 		    if (!mask->data.U8[i] && ((pixels->data.F32[i] - average) / deltas->data.F32[i] > max)) {
@@ -164,13 +165,15 @@
 		}
 		// Reject the pixel with the maximum deviation
-		if (max > reject) {    
+		if (max > reject) {
 		    mask->data.U8[maxIndex] = 1;
-		    ((psImage*)((*rejected)->data[maxIndex]))->data.F32[y][x] += 1.0;
+		    ((psImage*)((*rejected)->data[maxIndex]))->data.U8[y][x] += 1.0;
 		    // Re-do combination following rejection
 		    average = stacCombineMean(pixels, deltas, mask);
-		}
-	    } // Rejection iterations
-	    
-	    combined->data.F32[y][x] = stacCombineMean(pixels, deltas, mask);
+		} else {
+		    keepGoing = false;
+		}
+	    }
+	    
+	    combined->data.F32[y][x] = average;
 	}
     } // Iterating over output pixels
