Index: /trunk/psphot/src/psphotImageMedian.c
===================================================================
--- /trunk/psphot/src/psphotImageMedian.c	(revision 10284)
+++ /trunk/psphot/src/psphotImageMedian.c	(revision 10285)
@@ -118,7 +118,14 @@
             psStats *stats = psImageBackground(subset, submask, 0xff, 0.25, 0.75, MAX_SAMPLE_PIXELS,
 					       statsOption, rng);
-	    if (stats == NULL) {
+	    if (stats != NULL) {
+		if (stats->options & PS_STAT_ROBUST_QUARTILE) {
+		    modelData[iy][ix] = stats->robustMedian;
+		} else {	
+		    modelData[iy][ix] = psStatsGetValue(stats, statsOption);
+		}
+	    } else {
+		psStatsOptions fallback_option = PS_STAT_ROBUST_MEDIAN;
 		stats = psImageBackground(subset, submask, 0xff, 0.25, 0.75, MAX_SAMPLE_PIXELS,
-					  PS_STAT_ROBUST_MEDIAN, rng);
+					  fallback_option, rng);
 		if (stats == NULL) {
 		    psAbort(PS_FILE_LINE, "Failed to estimate background using ROBUST_MEDIAN for "
@@ -126,10 +133,7 @@
 			    subset->numRows, subset->numCols, subset->row0, subset->col0);
 		}
+		modelData[iy][ix] = psStatsGetValue (stats, PS_STAT_ROBUST_MEDIAN);
 	    }
-	    if (stats->options & PS_STAT_ROBUST_QUARTILE) {
-		modelData[iy][ix] = stats->robustMedian + SKY_BIAS;
-	    } else {	
-		modelData[iy][ix] = psStatsGetValue (stats, statsOption) + SKY_BIAS;
-	    }
+	    modelData[iy][ix] += SKY_BIAS;
 
             psFree (stats);
