Index: branches/eam_branches/ipp-20211108/psModules/src/imcombine/pmStack.c
===================================================================
--- branches/eam_branches/ipp-20211108/psModules/src/imcombine/pmStack.c	(revision 41909)
+++ branches/eam_branches/ipp-20211108/psModules/src/imcombine/pmStack.c	(revision 41919)
@@ -1579,5 +1579,4 @@
     int nGoodBits[16]; // accumulate the good pixel bits here for fuzzy logic
     psAssert (sizeof(psImageMaskType) == 2, "psImageMaskType is not the expected size");
-    memset (nGoodBits, 0, 16*sizeof(int));
 
     for (int y = minInputRows; y < maxInputRows; y++) {
@@ -1585,4 +1584,5 @@
 
 	    int nGood = 0; 
+	    memset (nGoodBits, 0, 16*sizeof(int));
 	    for (int i = 0; i < stackData->n; i++) {
 
@@ -1608,6 +1608,7 @@
 		// NOTE: since we have explicitly skipped the pixels with any bad bits, these are only
 		// the suspect bits (nGoodBits is a bit of a misnomer: it is more like 'nSuspectBitsForGoodInputs'
+		// NOTE: skip the full bit-by-bit check if we know the mask byte is empty
 		psImageMaskType value = 0x0001;
-		for (int nbit = 0; nbit < 16; nbit ++) {
+		for (int nbit = 0; mask->data.PS_TYPE_IMAGE_MASK_DATA[yIn][xIn] && (nbit < 16); nbit ++) {
 		    if (mask->data.PS_TYPE_IMAGE_MASK_DATA[yIn][xIn] & value) {
 			nGoodBits[nbit] ++;
@@ -1698,5 +1699,5 @@
 		expmaps->image->data.F32[y][x] = sum;
 	    }
-	    if (expmaps) { expmaps->mask->data.F32[y][x] = Ne - Ns; }
+	    if (expmaps) { expmaps->mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = Ne - Ns; }
 	}
     }
