Index: trunk/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 39361)
+++ trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 39362)
@@ -538,5 +538,5 @@
       haveStackObject = TRUE;
       
-      // find the PRIMARY measurement
+      // ** find the PRIMARY measurement
 
       // if we request the primary (USE_TREE_FOR_PRIMARY), this is true if the measurement is from the 
@@ -549,5 +549,19 @@
       }
 
-      // now choose the BEST measurements (may also be PRIMARY)
+      // ** now choose the BEST measurements (may also be PRIMARY)
+
+      // ensure that we at least have a single best measure 
+      if (stackBestMeasure == -1) stackBestMeasure = k;
+
+      // choose the best psfQFperf value for the BEST measurement
+      if (isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > psfQFbest)) {
+	psfQFbest = measure[k].psfQFperf;
+	stackBestMeasure = k;
+      }
+      // ... UNLESS psfQFperf > 0.98 for the primary, in which case just use the primary.
+      if ((measure[k].dbFlags & ID_MEAS_STACK_PRIMARY) && isfinite(measure[k].psfQFperf) && (measure[k].psfQFperf > 0.98)) {
+	psfQFbest = 1000; // force this to be the best entry
+	stackBestMeasure = k;
+      }
 
       if (measure[k].dbFlags & MEAS_BAD) SKIP_THIS_MEAS_STACK(Nbad); 
@@ -577,14 +591,4 @@
       if (isnan(Finst)) SKIP_THIS_MEAS_STACK(Ninst);
 
-      // choose the best psfQFperf value for the BEST measurement
-      if (measure[k].psfQFperf > psfQFbest) {
-	psfQFbest = measure[k].psfQFperf;
-	stackBestMeasure = k;
-      }
-      // ... UNLESS psfQFperf > 0.98 for the primary, in which case just use the primary.
-      if ((measure[k].dbFlags & ID_MEAS_STACK_PRIMARY) && (measure[k].psfQFperf > 0.98)) {
-	stackBestMeasure = k;
-      }
-
       // data quality assessment
       isBad |= (measure[k].photFlags & code->photomBadMask);
