Index: /branches/czw_branch/20160809/Ohana/src/relastro/include/relastro.h
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/relastro/include/relastro.h	(revision 39746)
+++ /branches/czw_branch/20160809/Ohana/src/relastro/include/relastro.h	(revision 39747)
@@ -453,4 +453,6 @@
 
 FitMode FIT_MODE;
+int USE_IRLS;
+int ALLOW_IRLS;
 
 RelastroOp RELASTRO_OP;
Index: /branches/czw_branch/20160809/Ohana/src/relastro/src/BootstrapOps.c
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/relastro/src/BootstrapOps.c	(revision 39746)
+++ /branches/czw_branch/20160809/Ohana/src/relastro/src/BootstrapOps.c	(revision 39747)
@@ -77,21 +77,21 @@
     case FIT_RESULT_RA:
       // result->Ro = median;
-      result->dRo = sigma;
+      result->dRo = MAX(sigma, result->dRo);
       break;
     case FIT_RESULT_DEC:
       // result->Do = median;
-      result->dDo = sigma;
+      result->dDo = MAX(sigma, result->dDo);
       break;
     case FIT_RESULT_uR:
       // result->uR = median;
-      result->duR = sigma;
+      result->duR = MAX(sigma, result->duR);
       break;
     case FIT_RESULT_uD:
       // result->uD = median;
-      result->duD = sigma;
+      result->duD = MAX(sigma, result->duD);
       break;
     case FIT_RESULT_PLX:
       // result->p = median;
-      result->dp = sigma;
+      result->dp = MAX(sigma, result->dp);
       break;
     default:
Index: /branches/czw_branch/20160809/Ohana/src/relastro/src/UpdateObjects.c
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/relastro/src/UpdateObjects.c	(revision 39746)
+++ /branches/czw_branch/20160809/Ohana/src/relastro/src/UpdateObjects.c	(revision 39747)
@@ -200,10 +200,19 @@
     // then run N_BOOTSTRAP_SAMPLES to measure the errors
     fitStats->fitdataPar->getError = !N_BOOTSTRAP_SAMPLES;
-    if (!FitPMandPar_IRLS (&fitPar, fitStats->fitdataPar, fitStats->points, fitStats->Npoints)) {
-      mode = FIT_PM_ONLY;
-      goto skipParallax;
-    }
-
-    if (N_BOOTSTRAP_SAMPLES) {
+    if (USE_IRLS) {
+      if (!FitPMandPar_IRLS (&fitPar, fitStats->fitdataPar, fitStats->points, fitStats->Npoints)) {
+	mode = FIT_PM_ONLY;
+	goto skipParallax;
+      }
+    } else {
+      if (!FitPMandPar_Basic (&fitPar, fitStats->fitdataPar, fitStats->points, fitStats->Npoints)) {
+	mode = FIT_PM_ONLY;
+	goto skipParallax;
+      }
+    }
+
+    // in the fits above, we have saved the formal error for the unmasked points.  
+    // if we do not have enough points for bootstrap, we will keep those errors
+    if (N_BOOTSTRAP_SAMPLES && (fitPar.Nfit >= PAR_MIN_NPTS_BOOT)) {
       fitStats->Nfit = 0;
       int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints);
@@ -218,5 +227,7 @@
 	fitStats->Nfit ++;
       }
-      // these calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above)
+      // These calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above)
+      // this call expects the fitted parameters to have the formal error set: it will apply the 
+      // max of the formal and bootstrap errors
       BootstrapRobustStats (&fitPar, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA);
       BootstrapRobustStats (&fitPar, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC);
@@ -273,9 +284,19 @@
     } else {
       fitStats->fitdataPM->getError = !N_BOOTSTRAP_SAMPLES;
-      if (!FitPM_IRLS (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) {
-	mode = FIT_AVERAGE;
-	goto justPosition;
-      }
-      if (N_BOOTSTRAP_SAMPLES) {
+      if (USE_IRLS) {
+	if (!FitPM_IRLS (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) {
+	  mode = FIT_AVERAGE;
+	  goto justPosition;
+	}
+      } else {
+	if (!FitPM_Basic (&fitPM, fitStats->fitdataPM, fitStats->points, fitStats->Npoints)) {
+	  mode = FIT_AVERAGE;
+	  goto justPosition;
+	}
+      }
+
+    // in the fits above, we have saved the formal error for the unmasked points.  
+    // if we do not have enough points for bootstrap, we will keep those errors
+      if (N_BOOTSTRAP_SAMPLES && (fitPM.Nfit >= PM_MIN_NPTS_BOOT)) {
 	fitStats->Nfit = 0;
 	int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints);
@@ -289,4 +310,7 @@
 	  fitStats->Nfit ++;
 	}
+      // These calls set the ERRORS on the fit parameters, not the fit values (set in IRLS above)
+      // this call expects the fitted parameters to have the formal error set: it will apply the 
+      // max of the formal and bootstrap errors
 	BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_RA);
 	BootstrapRobustStats (&fitPM, fitStats->fit, fitStats->Nfit, FIT_RESULT_DEC);
@@ -343,8 +367,18 @@
 	goto useBasic;
       }
-      if (!FitPosPMfixed_IRLS (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
-	// if the above fails, we need to clear the masks and try again below
-	FitPointsClearMasks (fitStats->points, fitStats->Npoints); 
-	// just calculate the weighted average
+      if (USE_IRLS) {
+	if (!FitPosPMfixed_IRLS (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) {
+	  // if the above fails, we need to clear the masks and try again below
+	  FitPointsClearMasks (fitStats->points, fitStats->Npoints); 
+	  // just calculate the weighted average
+	  if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 
+	    // if this fails, find a single unmasked point below
+	    goto doneWithFit;
+	  }
+	  average[0].flags |= ID_OBJ_USE_AVE;
+	  average[0].flags |= ID_OBJ_RAW_AVE;
+	  goto useBasic;
+	}
+      } else {
 	if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 
 	  // if this fails, find a single unmasked point below
@@ -360,5 +394,5 @@
 	int Nnomask = BootstrapSaveUnmasked (fitStats->nomask, fitStats->points, fitStats->Npoints);
 	if (Nnomask < POS_MIN_NPTS_BOOT) {
-	  // if the above fails, we need to clear the masks and try again below
+	  // XXX if the above fails, accept the formal error from unmasked points?
 	  FitPointsClearMasks (fitStats->points, fitStats->Npoints); 
 	  if (!FitPosPMfixed_Basic (&fitPos, fitStats->fitdataPos, fitStats->points, fitStats->Npoints)) { 
Index: /branches/czw_branch/20160809/Ohana/src/relastro/src/args.c
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/relastro/src/args.c	(revision 39746)
+++ /branches/czw_branch/20160809/Ohana/src/relastro/src/args.c	(revision 39747)
@@ -176,4 +176,14 @@
       exit (2);
     }
+  }
+
+  // for fitting objects, this is always the same as 'ALLOW_IRLS' below, but for fitting
+  // images, this is set to FALSE while doing the fit for the image parameters
+  USE_IRLS = TRUE;  
+  ALLOW_IRLS = TRUE;
+  if ((N = get_argument (argc, argv, "-no-irls"))) {
+    remove_argument (N, &argc, argv);
+    USE_IRLS = FALSE;
+    ALLOW_IRLS = FALSE;
   }
 
Index: /branches/czw_branch/20160809/Ohana/src/relastro/src/relastro_images.c
===================================================================
--- /branches/czw_branch/20160809/Ohana/src/relastro/src/relastro_images.c	(revision 39746)
+++ /branches/czw_branch/20160809/Ohana/src/relastro/src/relastro_images.c	(revision 39747)
@@ -64,4 +64,6 @@
 
   // XXX NOTE : for 2mass reset, photcodesKeep should now limit to 2MASS measurements
+
+  USE_IRLS = FALSE;  // do not use IRLS yet -- leads to excessive outlier rejections in the loops
 
   /* major modes */
@@ -161,4 +163,5 @@
   // iterate over catalogs to make detection coordinates consistant
   if (APPLY_OFFSETS) {
+    USE_IRLS = ALLOW_IRLS;  // now that we have fitted the images, choose the user's option
     UpdateObjectOffsets (skylist, 0, NULL);
   }
