Index: trunk/psModules/src/detrend/pmBias.c
===================================================================
--- trunk/psModules/src/detrend/pmBias.c	(revision 19299)
+++ trunk/psModules/src/detrend/pmBias.c	(revision 19432)
@@ -23,5 +23,5 @@
     PS_ASSERT_THREAD_JOB_NON_NULL(job, false);
     pmReadout *in = job->args->data[0];
-    pmReadout *sub = job->args->data[1];
+    const pmReadout *sub = job->args->data[1];
     float scale  = PS_SCALAR_VALUE(job->args->data[2],F32);
     int xOffset  = PS_SCALAR_VALUE(job->args->data[3],S32);
@@ -29,14 +29,14 @@
     int rowStart = PS_SCALAR_VALUE(job->args->data[5],S32);
     int rowStop  = PS_SCALAR_VALUE(job->args->data[6],S32);
-    bool status = pmBiasSubtractScan (in, sub, scale, xOffset, yOffset, rowStart, rowStop);
-    return status;
-}
-
-bool pmBiasSubtractScan (pmReadout *in, pmReadout *sub, float scale, int xOffset, int yOffset, int rowStart, int rowStop) {
-
+    return pmBiasSubtractScan(in, sub, scale, xOffset, yOffset, rowStart, rowStop);
+}
+
+bool pmBiasSubtractScan(pmReadout *in, const pmReadout *sub, float scale,
+                        int xOffset, int yOffset, int rowStart, int rowStop)
+{
     psImage *inImage  = in->image;      // The input image
     psImage *inMask   = in->mask;       // The input mask
-    psImage *subImage = sub->image;     // The image to be subtracted
-    psImage *subMask  = sub->mask;      // The mask for the subtraction image
+    const psImage *subImage = sub->image; // The image to be subtracted
+    const psImage *subMask  = sub->mask; // The mask for the subtraction image
 
     if (scale == 1.0) {
@@ -62,5 +62,6 @@
 }
 
-// pmBiasSubtractFrame(): this routine will take as input a readout for the input image and a readout for the bias
+// pmBiasSubtractFrame():
+// this routine will take as input a readout for the input image and a readout for the bias
 // image.  The bias image is subtracted in place from the input image.
 bool pmBiasSubtractFrame(pmReadout *in, // Input readout
@@ -129,41 +130,33 @@
 
     for (int rowStart = 0; rowStart < inImage->numRows; rowStart += scanRows) {
-      int rowStop = PS_MIN (rowStart + scanRows, inImage->numRows);
-
-      if (threaded) {
-          // allocate a job, construct the arguments for this job
-          psThreadJob *job = psThreadJobAlloc ("PSMODULES_DETREND_BIAS");
-          psArrayAdd (job->args, 1, in);
-          psArrayAdd (job->args, 1, sub);
-          PS_ARRAY_ADD_SCALAR (job->args, scale, PS_TYPE_F32);
-          PS_ARRAY_ADD_SCALAR (job->args, xOffset, PS_TYPE_S32);
-          PS_ARRAY_ADD_SCALAR (job->args, yOffset, PS_TYPE_S32);
-          PS_ARRAY_ADD_SCALAR (job->args, rowStart, PS_TYPE_S32);
-          PS_ARRAY_ADD_SCALAR (job->args, rowStop, PS_TYPE_S32);
-
-          // ppImageDetrendReadout(config, options, view)
-          if (!psThreadJobAddPending (job)) {
-              psFree(job);
-              return false;
-          }
-          psFree(job);
-      } else {
-          pmBiasSubtractScan (in, sub, scale, xOffset, yOffset, rowStart, rowStop);
-      }
+        int rowStop = PS_MIN(rowStart + scanRows, inImage->numRows);
+
+        if (threaded) {
+            // allocate a job, construct the arguments for this job
+            psThreadJob *job = psThreadJobAlloc("PSMODULES_DETREND_BIAS");
+            psArrayAdd(job->args, 1, in);
+            psArrayAdd(job->args, 1, sub);
+            PS_ARRAY_ADD_SCALAR(job->args, scale, PS_TYPE_F32);
+            PS_ARRAY_ADD_SCALAR(job->args, xOffset, PS_TYPE_S32);
+            PS_ARRAY_ADD_SCALAR(job->args, yOffset, PS_TYPE_S32);
+            PS_ARRAY_ADD_SCALAR(job->args, rowStart, PS_TYPE_S32);
+            PS_ARRAY_ADD_SCALAR(job->args, rowStop, PS_TYPE_S32);
+
+            if (!psThreadJobAddPending(job)) {
+                psFree(job);
+                return false;
+            }
+            psFree(job);
+        } else if (!pmBiasSubtractScan(in, sub, scale, xOffset, yOffset, rowStart, rowStop)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to apply bias correction.");
+            return false;
+        }
     }
 
     if (threaded) {
         // wait here for the threaded jobs to finish
-        if (!psThreadPoolWait(false)) {
-            psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
-            return false;
-        }
-        fprintf (stderr, "success for threaded jobs\n");
-
-        // each job records its own goodPixel values; sum them here
-        // we have only supplied one type of job, so we can assume the types here
-        psThreadJob *job = NULL;
-        while ((job = psThreadJobGetDone()) != NULL) {
-            psFree (job);
+        if (!psThreadPoolWait(true)) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to apply bias correction.");
+            return false;
         }
     }
