Index: trunk/psphot/src/apply_psf_model.c
===================================================================
--- trunk/psphot/src/apply_psf_model.c	(revision 4129)
+++ trunk/psphot/src/apply_psf_model.c	(revision 4216)
@@ -4,5 +4,4 @@
 // PSFSTAR objects will be refitted
 // run this function to a specific flux limit?
-
 
 bool apply_psf_model (psImage *image, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) 
@@ -18,12 +17,7 @@
     float FIT_NSIGMA  = psMetadataLookupF32 (&status, config, "FIT_NSIGMA");
     float FIT_PADDING = psMetadataLookupF32 (&status, config, "FIT_PADDING");
-
-    float XBORDER  = psMetadataLookupF32 (&status, config, "XBORDER");
-    float YBORDER  = psMetadataLookupF32 (&status, config, "YBORDER");
-    psRegion *keep = psRegionAlloc (XBORDER, -XBORDER, YBORDER, -YBORDER);
-    keep           = psRegionForImage (keep, image, keep);
-
     float shapeNsigma = psMetadataLookupF32 (&status, config, "PSF_SHAPE_NSIGMA");
-    // float snFaint     = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM");
+    float snFaint     = psMetadataLookupF32 (&status, config, "FAINT_SN_LIM");
+    float OUTER       = psMetadataLookupF32 (&status, config, "OUTER_RADIUS");
 
     // set the object surface-brightness limit for fitted pixels
@@ -46,4 +40,6 @@
 	// set PSF parameters for this model
 	model  = psModelFromPSF (model, psf);
+	x = model->params->data.F32[2];
+	y = model->params->data.F32[3];
 
 	// set the fit radius based on the object flux limit and the model
@@ -54,12 +50,20 @@
 	  continue;
 	}
-	    
-	// set the valid/invalid pixel mask
-	pmSourceSetPixelCircle (source, image, model->radius);
-	pmSourceMaskRegion (source, keep);
+	
+	// mask off saturated pixels (move this to setup?)
 	pmSourceMaskSaturated (source, SATURATE);
 
-	// fit as PSF, not FLT (skip poor fits)
-	if (!pmSourceFitModel (source, model, true)) continue;
+	// check if we need to redefine the pixels
+	if (model->radius > OUTER) {
+	  // allocate image, noise, mask arrays for each peak (square of radius OUTER)
+	  pmSourceDefinePixels (source, imdata, x, y, OUTER);
+	}
+
+	// set the valid/invalid pixel mask
+	psImageKeepCircle (source->mask, x, y, model->radius, OR, 0x80);
+	status = pmSourceFitModel (source, model, true);
+	psImageKeepCircle (source->mask, x, y, model->radius, AND, 0x7f);
+	if (!status) continue;
+
 	source->modelPSF = model;
 	Niter += model[0].nIter;
