Index: trunk/psphot/src/psphotChoosePSF.c
===================================================================
--- trunk/psphot/src/psphotChoosePSF.c	(revision 5772)
+++ trunk/psphot/src/psphotChoosePSF.c	(revision 5802)
@@ -66,11 +66,19 @@
 	}
     }
-    // XXX EAM : need to unflag the PSF stars which are not used to build the PSF
-    // XXX EAM : each pmPSFtry needs to have its own mask array
+    
+    // use the best model:
+    try = models->data[bestN];
 
-    // keep only the selected model:
-    try = models->data[bestN];
+    // unset the PSFSTAR flag for stars not used for PSF model
+    for (int i = 0; i < try->sources->n; i++) {
+	pmSource *source = try->sources->data[i];
+	if (try->mask->data.U8[i] & PSFTRY_MASK_FLT_FAIL) {
+	    source->mode &= ~PM_SOURCE_PSFSTAR;
+	}
+    }
+
+    // save only the best model;
     pmPSF *psf = psMemCopy(try->psf);
-    psFree (models);				 // keep only the pmPSF resulting from this analysis
+    psFree (models);
 
     modelName = pmModelGetType (psf->type);
