Index: /branches/eam_branches/ipp-ppmerge-20241229/psModules/src/detrend/pmDark.c
===================================================================
--- /branches/eam_branches/ipp-ppmerge-20241229/psModules/src/detrend/pmDark.c	(revision 42773)
+++ /branches/eam_branches/ipp-ppmerge-20241229/psModules/src/detrend/pmDark.c	(revision 42774)
@@ -252,8 +252,8 @@
     }
 
+# if (PS_TRACE_ON)
     if (psTraceGetLevel("psModules.detrend") > 9) {
         for (int i = 0; i < inputs->n; i++) {
             psVector *val = values->data[i];
-            (void) val; // avoid unused variable message when tracing is compiled out
             for (int j = 0; j < ordinates->n; j++) {
                 psTrace("psModules.detrend", 9, "Image %d, ordinate %d: %f\n", i, j, val->data.F32[j]);
@@ -261,4 +261,5 @@
         }
     }
+# endif
 
     int numTerms = 1;                   // Number of terms in polynomial
@@ -292,7 +293,9 @@
         pmReadout *readout = output->readouts->data[i]; // Readout to update
         if (!readout) {
-            readout = output->readouts->data[i] = pmReadoutAlloc(output);
-        }
-
+  	    // pmReadoutAlloc places a reference to the readout on cell->readouts
+	    // and returns a second mem reference to the readout
+            readout = pmReadoutAlloc(output);
+	    psFree (readout); // free the extra mem reference returned by pmReadoutAlloc
+        }
         pmReadoutStackDefineOutput(readout, col0, row0, numCols, numRows, false, false, 0);
         psTrace("psModules.imcombine", 7, "Output minimum: %d,%d\n", col0, row0);
@@ -469,8 +472,4 @@
 	      for (int m = 0; m < poly->deviations->n; m++) {
 		logL->data.F64[k] += pow(poly->deviations->data.F32[m] / polySig->stdevFit,2);
-/* 		if ((xOut == 20) && (yOut == 256)) { */
-/* 		  psTrace("psModules.detrend",3,"pmDarkCombine DEV: %d %d: input %d models: Norders: %d logL: %g value: %g\n", */
-/* 			  xOut,yOut,m,k,logL->data.F64[k],poly->deviations->data.F32[m]); */
-/* 		} */
 	      }
 	      if (k > 0) {
@@ -487,15 +486,13 @@
 	      k_best = 1;
 	    }
-/* 	    k_best = 1; */
+
 	    // Select the polynomial that seems best.
 	    psPolynomialMD *poly = poly_set->data[k_best];
 	      
-	    //            for (int k = 0; k < poly->coeff->n; k++) {
 	    for (int k = 0; k < max_orders->n + 1; k++) { // There is one more coefficient than is stored here.
                 pmReadout *ro = output->readouts->data[k]; // Readout of interest
 		if (k < poly->coeff->n) {
 		  ro->image->data.F32[yOut][xOut] = poly->coeff->data.F64[k];
-		}
-		else {
+		} else {
 		  ro->image->data.F32[yOut][xOut] = 0.0;
 		}
