Index: trunk/psphot/src/psphotFitSourcesLinearStack.c
===================================================================
--- trunk/psphot/src/psphotFitSourcesLinearStack.c	(revision 31452)
+++ trunk/psphot/src/psphotFitSourcesLinearStack.c	(revision 32348)
@@ -64,4 +64,20 @@
           // turn this bit off and turn it on again if we keep this source
           source->mode &= ~PM_SOURCE_MODE_LINEAR_FIT;
+
+	  // skip non-astronomical objects (very likely defects)
+	  if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
+	  if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
+
+	  // do not include CRs in the full ensemble fit
+	  if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;
+
+	  // do not include MOMENTS_FAILURES in the fit
+	  if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue;
+
+	  if (final) {
+	      if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue;
+	  } else {
+	      // if (source->mode & PM_SOURCE_MODE_BLEND) continue;
+	  }
 
           // generate model for sources without, or skip if we can't
@@ -83,5 +99,17 @@
 	  }
 
-          source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
+	  bool isPSF = false;
+	  pmModel *model = pmSourceGetModel (&isPSF, source);
+
+	  // clear the 'mark' pixels and remask on the fit aperture 
+	  psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
+	  psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, model->fitRadius, "OR", markVal);
+
+	  // we call this function multiple times. for the first time, we have only PSF models for all objects
+	  // the second time has extended sources.  If we ever fit the PSF model, we should raise this bit
+	  source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
+	  if (isPSF) {
+	      source->mode |= PM_SOURCE_MODE_PSFMODEL;
+	  }	    
           psArrayAdd (fitSources, 100, source);
         }
@@ -166,4 +194,7 @@
         model->params->data.F32[PM_PAR_I0] = norm->data.F32[i];
         model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i];
+
+	// clear the 'mark' pixels so the subtraction covers the full window
+        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
 
         // subtract object
@@ -190,5 +221,5 @@
     psFree (errors);
 
-    psLogMsg ("psphot.ensemble", PS_LOG_INFO, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot.linear"));
+    psLogMsg ("psphot.ensemble", PS_LOG_WARN, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot.linear"));
     return true;
 }
