Index: branches/eam_branches/ipp-dev-20210817/psModules/src/astrom/pmAstrometryObjects.c
===================================================================
--- branches/eam_branches/ipp-dev-20210817/psModules/src/astrom/pmAstrometryObjects.c	(revision 41835)
+++ branches/eam_branches/ipp-dev-20210817/psModules/src/astrom/pmAstrometryObjects.c	(revision 41836)
@@ -354,11 +354,11 @@
 
 	bool isValid = true;
-	isValid = isValid & isfinite (xFit->data.F32[i]);
-	isValid = isValid & isfinite (yFit->data.F32[i]);
+	isValid = isValid & isfinite (x->data.F32[i]);
+	isValid = isValid & isfinite (y->data.F32[i]);
 	isValid = isValid & isfinite (xRes->data.F32[i]);
 	isValid = isValid & isfinite (yRes->data.F32[i]);
 	if (isValid) {
-	  psVectorAppend (xPosValid, xFit->data.F32[i]);
-	  psVectorAppend (yPosValid, yFit->data.F32[i]);
+	  psVectorAppend (xPosValid, x->data.F32[i]);
+	  psVectorAppend (yPosValid, y->data.F32[i]);
 	  psVectorAppend (xResValid, xRes->data.F32[i]);
 	  psVectorAppend (yResValid, yRes->data.F32[i]);
@@ -391,4 +391,5 @@
       results->dXsys   = results->dYsys   = NAN;
       results->dXrange = results->dYrange = NAN;
+      results->dXstdev = results->dYstdev = NAN;
     } else {
       results->dXsys = psVectorSystematicError (xResGood, xErr, 0.05);
@@ -427,10 +428,12 @@
 
 # define VAL_COUNT 9.0
-# define MIN_COUNT 7.0
+# define MIN_COUNT 5.0
 
 float pmAstrom2DSystematics (psVector *xPos, psVector *yPos, psVector *value) {
 
     // pre-filter the values to ensure no NANs, other invalid
-    if (xPos->n < VAL_COUNT*2*2) { return NAN; }
+    if (xPos->n < VAL_COUNT*2*2) {
+      return NAN;
+    }
 
     // generate a grid covering the full range of x,y and measure the median value in each
@@ -455,6 +458,10 @@
     float yStep = Ncell / (yMax - yMin);
   
-    if (isnan(xStep)) { return NAN; }
-    if (isnan(yStep)) { return NAN; }
+    if (isnan(xStep)) {
+      return NAN;
+    }
+    if (isnan(yStep)) {
+      return NAN;
+    }
 
     psArray *xBin = psArrayAlloc (Ncell);
@@ -487,5 +494,6 @@
 	for (int iy = 0; iy < Ncell; iy++) {
 	    psVector *Bin = yBin->data[iy];
-      
+	    if (Bin->n < MIN_COUNT) { continue; }
+
 	    // psVectorStats resets stats so we can call this repeatedly
 	    psVectorStats (stats, Bin, NULL, NULL, 0); 
@@ -499,4 +507,8 @@
     psVectorStats (stats, sample, NULL, NULL, 0); 
     float result = stats->sampleStdev;
+
+    if (!isfinite(stats->sampleStdev)) {
+      fprintf (stderr, "*** bad solution ***\n");
+    }
 
     // NOTE: the elements of xBin are freed automatically, which extends down to the vectors
Index: branches/eam_branches/ipp-dev-20210817/psModules/src/objects/pmSourceIO_CMF.c.in
===================================================================
--- branches/eam_branches/ipp-dev-20210817/psModules/src/objects/pmSourceIO_CMF.c.in	(revision 41835)
+++ branches/eam_branches/ipp-dev-20210817/psModules/src/objects/pmSourceIO_CMF.c.in	(revision 41836)
@@ -761,6 +761,6 @@
 bool pmSourcesWrite_CMF_@CMFMODE@ (psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, psMetadata *tableHeader, char *extname, psMetadata *recipe)
 {
-    // bool status = pmSourcesWrite_CMF_@CMFMODE@_Old (fits, readout, sources, imageHeader, tableHeader, extname, recipe);
-    bool status = pmSourcesWrite_CMF_@CMFMODE@_New (fits, readout, sources, imageHeader, tableHeader, extname, recipe);
+  // bool status = pmSourcesWrite_CMF_@CMFMODE@_Old (fits, readout, sources, imageHeader, tableHeader, extname, recipe);
+     bool status = pmSourcesWrite_CMF_@CMFMODE@_New (fits, readout, sources, imageHeader, tableHeader, extname, recipe);
     return status;
 }
@@ -1195,6 +1195,6 @@
 
 psArray *pmSourcesRead_CMF_@CMFMODE@ (psFits *fits, psMetadata *header) {
-//  psArray *array = pmSourcesRead_CMF_@CMFMODE@_Old (fits, header);
-    psArray *array = pmSourcesRead_CMF_@CMFMODE@_New (fits, header);
+  // psArray *array = pmSourcesRead_CMF_@CMFMODE@_Old (fits, header);
+      psArray *array = pmSourcesRead_CMF_@CMFMODE@_New (fits, header);
     return array;
 }
Index: branches/eam_branches/ipp-dev-20210817/psModules/src/objects/pmSourceIO_Ghosts.c
===================================================================
--- branches/eam_branches/ipp-dev-20210817/psModules/src/objects/pmSourceIO_Ghosts.c	(revision 41835)
+++ branches/eam_branches/ipp-dev-20210817/psModules/src/objects/pmSourceIO_Ghosts.c	(revision 41836)
@@ -136,5 +136,5 @@
     pmFPAview *view = pmFPAviewAlloc (0);
 
-    //We need to check whether we are dealing with an old style ghost_model, or a new style model. Check if the mirror_rad polynomial exists
+    // We need to check whether we are dealing with an old style ghost_model, or a new style model. Check if the mirror_rad polynomial exists
     float mirCheck = 0;
     md = psMetadataLookupMetadata (&status, ghostModel, "GHOST.MIRROR.RAD"); 
@@ -153,5 +153,4 @@
     GET_1D_POLY ("GHOST.INNER.MINOR", innerMinor);
 
-
     // select the input astrometry data (also carries the refstars)
     pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSASTRO.INPUT");
@@ -211,5 +210,6 @@
      	                double theta0 = atan2(ref->FP->y,ref->FP->x);
 
-                        if(mirCheck) {
+			// EAM: XXX we should just use the existence of mirrorRad (!= NULL) instead of carrying a different bool
+                        if (mirCheck) {
                             //TdB: first mirror the reference star positions (around the 0,0 pixel) using the radial offset coefficients and the ghost/star angle
 		            double ghost_offset_rad = psPolynomial1DEval (mirrorRad, rSrc);
@@ -220,6 +220,5 @@
 		            ghost->FP->x = ghost_x_fpa_mirror + psPolynomial2DEval(centerX, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
 		            ghost->FP->y = ghost_y_fpa_mirror + psPolynomial2DEval(centerY, ghost_x_fpa_mirror, ghost_y_fpa_mirror);
-                        }  
-                        if(!mirCheck) {
+                        } else {
                             //Use the old-style ghost position determination
                             ghost->FP->x = -ref->FP->x + psPolynomial2DEval(centerX, -ref->FP->x, -ref->FP->y);
@@ -303,4 +302,5 @@
     	psFree (outerMajor);
     	psFree (outerMinor);
+    	psFree (mirrorRad);
     	psFree (ghostModel);
     	psFree (view);
@@ -327,4 +327,5 @@
     psFree (outerMajor);
     psFree (outerMinor);
+    psFree (mirrorRad);
     psFree (ghostModel);
     psFree (view);
