Index: trunk/psLib/src/fits/psFits.c
===================================================================
--- trunk/psLib/src/fits/psFits.c	(revision 41520)
+++ trunk/psLib/src/fits/psFits.c	(revision 41521)
@@ -773,4 +773,5 @@
     int status = 0;                     // cfitsio status
     int comptype = 0;                   // cfitsio compression type
+
     if (fits_get_compression_type(fits->fd, &comptype, &status)) {
         psFitsError(status, true, "Unable to get compression type.");
Index: trunk/psLib/src/fits/psFitsImage.c
===================================================================
--- trunk/psLib/src/fits/psFitsImage.c	(revision 41520)
+++ trunk/psLib/src/fits/psFitsImage.c	(revision 41521)
@@ -292,5 +292,5 @@
                                           psRandom *rng, // Random number generator
                                           bool newScaleZero // Determine a new BSCALE and BZERO?
-                                          )
+    )
 {
     psAssert(bscale, "impossible");
@@ -307,6 +307,4 @@
 
     psFitsOptions *options = fits->options; // Options for FITS writing
-
-    // psMemCheckCorruption (stderr, true); // 1
 
     // Can't PLIO compress U16,U32,U64 directly, so convert them
@@ -331,6 +329,4 @@
     }
 
-    // psMemCheckCorruption (stderr, true); // 1x
-
     // Custom floating-point
     if (PS_IS_PSELEMTYPE_REAL(image->type.type) && options->conventions.psBitpix &&
@@ -345,9 +341,7 @@
     }
 
-    // psMemCheckCorruption (stderr, true); // 2
-
     // Quantise floating-point images
     if (PS_IS_PSELEMTYPE_REAL(image->type.type) && options->bitpix > 0) {
-        if (newScaleZero) {
+	if (newScaleZero) {
             // Choose an appropriate BSCALE and BZERO
 	    if (!psFitsScaleDetermine(bscale, bzero, boffset, bsoften, blank, image, mask, maskVal, fits)) {
@@ -357,49 +351,24 @@
 		return psMemIncrRefCounter((psImage*)image);
 	    }
-        } else {
+	} else {
 	    // Don't want to muck with the current BSCALE and BZERO.  Get the current values and use those.
 	    int status = 0;                 // Status of cfitsio
 	    if (fits_read_key_dbl(fits->fd, "BSCALE", bscale, NULL, &status) && status != KEY_NO_EXIST) {
-                psFitsError(status, true, "Unable to read header.");
-                return NULL;
+		psFitsError(status, true, "Unable to read header.");
+		return NULL;
             }
-
-	    // psMemCheckCorruption (stderr, true); // 2x
 
             status = 0;
             if (fits_read_key_dbl(fits->fd, "BZERO", bzero, NULL, &status) && status != KEY_NO_EXIST) {
-                psFitsError(status, true, "Unable to read header.");
-                return NULL;
+		psFitsError(status, true, "Unable to read header.");
+		return NULL;
             }
             status = 0;
             if (*bscale == 0.0) {
-                psError(PS_ERR_IO, true,
-                        "Supposed to use old values of BSCALE and BZERO, but they don't exist.");
-                return NULL;
+		psError(PS_ERR_IO, true,
+			"Supposed to use old values of BSCALE and BZERO, but they don't exist.");
+		return NULL;
             }
-
-	    // psMemCheckCorruption (stderr, true); // 3
-
-        }
-
-	// XXX this test triggers the pswarp memory corruption problem.  you need to include "psThread.h" above to activate this
-	// for (int nx = 0; nx < 3; nx++) { 
-	//     psList *pending = psThreadGetPendingQueue();
-	//     if (pending && pending->head) {
-	// 	fprintf (stderr, "thread jobs are still pending...\n");
-	//     }
-	//     // XXX can we mess up the memory?
-	//     psImage *temp1 = psImageAlloc(image->numCols, image->numRows, PS_TYPE_F32);
-	//     fprintf (stderr, "corruption check set 1\n");
-	//     psMemCheckCorruption (stderr, true);
-	//     psImageInit (temp1, 2.0);
-	//     psFree (temp1);
-	//     fprintf (stderr, "corruption check set 2\n");
-	//     psMemCheckCorruption (stderr, true);
-	// }
-
-	// fprintf (stderr, "corruption check psFitsInsertImageWithMask\n");
-	// psMemCheckCorruption (stderr, true);
-
+	}
         psImage *out = psFitsScaleForDisk(image, fits, *bscale, *bzero, *boffset, *bsoften, rng);
         return out;
@@ -407,15 +376,13 @@
 
     // Choose the appropriate output type, given the input type and desired bits per pixel
-#define CONVERT_TYPE_INT_CASE(OUTTYPE, INTYPE, BITPIX) \
-  case BITPIX: \
-    OUTTYPE = PS_IS_PSELEMTYPE_UNSIGNED(INTYPE) ? PS_TYPE_U##BITPIX : PS_TYPE_S##BITPIX; \
+#define CONVERT_TYPE_INT_CASE(OUTTYPE, INTYPE, BITPIX)			\
+    case BITPIX:							\
+	OUTTYPE = PS_IS_PSELEMTYPE_UNSIGNED(INTYPE) ? PS_TYPE_U##BITPIX : PS_TYPE_S##BITPIX; \
     break;
-#define CONVERT_TYPE_FLOAT_CASE(OUTTYPE, BITPIX) \
-  case -BITPIX: /* Note the use of the negative sign */ \
-    OUTTYPE = PS_TYPE_F##BITPIX; \
+#define CONVERT_TYPE_FLOAT_CASE(OUTTYPE, BITPIX)		\
+    case -BITPIX: /* Note the use of the negative sign */	\
+	OUTTYPE = PS_TYPE_F##BITPIX;				\
     break;
 
-
-    // psMemCheckCorruption (stderr, true); // 4
 
     *bscale = 1.0;
@@ -501,5 +468,5 @@
 
     // No need to apply the BSCALE, BZERO because cfitsio does this for us
-
+    
     return true;
 }
@@ -668,6 +635,4 @@
     }
 
-    // fprintf (stderr, "calling psFitsInsertImageWithMask for %s, %lx, %lx\n", fits->fd->Fptr->filename, (long int) image, (long int) mask);
-
     int numCols = image->numCols;       // Number of columns for image
     int numRows = image->numRows;       // Number of rows for image
@@ -682,12 +647,6 @@
     psFitsFloat floatType;              // Custom floating-point convention type
 
-    // psMemCheckCorruption (stderr, true);
-
     psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &boffset, &bsoften, &blank, &floatType, 
 						   fits, image, mask, maskVal, NULL, true); // Image to write out
-
-    // psMemCheckCorruption (stderr, true);
-
-    // fprintf (stderr, "allocated in psFitsInsertImageWithMask %s, %lx\n", fits->fd->Fptr->filename, (long int) diskImage);
 
     if (!diskImage) {
@@ -726,15 +685,4 @@
 
     psFitsOptions *options = fits->options; // FITS I/O options
-/*     if (options) { */
-/*       if (options->scaling == PS_FITS_SCALE_LOG_RANGE) { */
-/* 	fprintf(stderr,"it has the scaling I expect\n"); */
-/*       } */
-/*       else { */
-/* 	fprintf(stderr,"it does nto have the scaling I expect\n"); */
-/*       } */
-/*     } */
-/*     else { */
-/*       fprintf(stderr,"options is null, apparently? \n"); */
-/*     } */
      
     psAssert(!useRequestedScale || !options || bitPix == options->bitpix || options->bitpix == 0,
@@ -830,5 +778,5 @@
 
     if (isfinite(bzero) && isfinite(bscale) && (bscale != 0.0)) {
-        fits_write_key_dbl(fits->fd, "BZERO", bzero, 12,
+	fits_write_key_dbl(fits->fd, "BZERO", bzero, 12,
                            "Scaling: TRUE = BZERO + BSCALE * DISK", &status);
         fits_write_key_dbl(fits->fd, "BSCALE", bscale, 12,
@@ -885,5 +833,5 @@
     if (image->parent == NULL) {
         // if no parent, assume that the image data is contiguous
-        fits_write_img(fits->fd, dataType, 1, numCols*numRows, diskImage->data.V[0], &status);
+	fits_write_img(fits->fd, dataType, 1, numCols*numRows, diskImage->data.V[0], &status);
     } else {
         // image data may not be contiguous; write one row at a time
Index: trunk/psLib/src/fits/psFitsScale.c
===================================================================
--- trunk/psLib/src/fits/psFitsScale.c	(revision 41520)
+++ trunk/psLib/src/fits/psFitsScale.c	(revision 41521)
@@ -131,4 +131,5 @@
     psStats *stats = psStatsAlloc(MEAN_STAT | STDEV_STAT); // Statistics object
     double mean, stdev;                                    // Mean and standard deviation
+
     if (!psImageBackground(stats, NULL, image, mask, maskVal, rng)) {
         // It could be because the image is entirely masked, in which case we don't want to error
@@ -919,8 +920,8 @@
       case PS_FITS_SCALE_STDEV_NEGATIVE:
       case PS_FITS_SCALE_STDEV_BOTH:
-        if (!scaleStdev(bscale, bzero, image, mask, maskVal, options)) {
+	if (!scaleStdev(bscale, bzero, image, mask, maskVal, options)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to set BSCALE and BZERO from stdev");
             return false;
-        }
+	}
         break;
       case PS_FITS_SCALE_LOG_RANGE:
