Index: branches/eam_branches/relphot.20210521/src/TGroupOps.c
===================================================================
--- branches/eam_branches/relphot.20210521/src/TGroupOps.c	(revision 41625)
+++ branches/eam_branches/relphot.20210521/src/TGroupOps.c	(revision 41637)
@@ -1265,8 +1265,8 @@
  */
 
-static float MinMaxChiSq = NAN;
-static float MaxMaxChiSq = 6.0;
-static float MinMaxScatter = NAN;
-static float MaxMaxScatter = 0.1;
+static float MinChiSqLim = NAN;
+static float MaxChiSqLim = NAN;
+static float MinScatterLim = NAN;
+static float MaxScatterLim = NAN;
 
 void clean_tgroups () {
@@ -1277,4 +1277,7 @@
 
   if (VERBOSE) fprintf (stderr, "marking poor tgroups\n");
+
+  if (isnan (MaxChiSqLim))   MaxChiSqLim   = NIGHT_CHISQ;
+  if (isnan (MaxScatterLim)) MaxScatterLim = NIGHT_SCATTER;
 
   ALLOCATE (mlist, double, NtgroupTimes*Nphotcodes);
@@ -1300,13 +1303,13 @@
   liststats (mlist, NULL, NULL, N, &stats);
   float ChiSqUpper90 = stats.Upper90; 
-  if (isnan (MinMaxChiSq)) MinMaxChiSq = 2.0*stats.median;
-  float MaxChiSq = MIN(MaxMaxChiSq, MAX (MinMaxChiSq, ChiSqUpper90)); // the upper limit should be between MinMaxChiSq and MaxMaxChiSq 
+  if (isnan (MinChiSqLim)) MinChiSqLim = 2.0*stats.median;             // chi-square cut cannot fall below this value (even if this is > MaxChiSqLim)
+  float ChiSqLimit = MAX(MinChiSqLim, MIN(MaxChiSqLim, ChiSqUpper90)); // chi-square cut should be between MinChiSqLim and MaxChiSqLim
 
   liststats (slist, NULL, NULL, N, &stats);
   float ScatterUpper90 = stats.Upper90; 
-  if (isnan (MinMaxScatter)) MinMaxScatter = 2.0*stats.median;
-  float MaxScatter = MIN(MaxMaxScatter, MAX (MinMaxScatter, ScatterUpper90));
-
-  fprintf (stderr, "TGROUPS: Max ChiSq: %f, Max Scatter: %f | ChiSquare Upper 90: %f, Scatter Upper 90: %f\n", MaxChiSq, MaxScatter, ChiSqUpper90, ScatterUpper90);
+  if (isnan (MinScatterLim)) MinScatterLim = 2.0*stats.median;         // scatter cut cannto fall below this value (even if this is > MaxScatterLim)
+  float ScatterLimit = MAX(MinScatterLim, MIN(MaxScatterLim, ScatterUpper90));
+
+  fprintf (stderr, "TGROUPS: ChiSqLimit: %f, ScatterLimit: %f | ChiSquare Upper 90: %f, Scatter Upper 90: %f\n", ChiSqLimit, ScatterLimit, ChiSqUpper90, ScatterUpper90);
   
   int Ntotal = 0, Npoor = 0, Nmark = 0, Nscatter = 0, Nchisq = 0, NfewNights = 0, NfewExp = 0;
@@ -1337,10 +1340,10 @@
       }
       // scatter too large
-      if (tgroup[j].stdev > MaxScatter) {
+      if (tgroup[j].stdev > ScatterLimit) {
 	mark = TRUE;
 	Nscatter ++;
       }
       // chisq too large
-      if (tgroup[j].McalChiSq > MaxChiSq) {
+      if (tgroup[j].McalChiSq > ChiSqLimit) {
 	mark = TRUE;
 	Nchisq ++;
