Index: trunk/ppStack/src/ppStackFinish.c
===================================================================
--- trunk/ppStack/src/ppStackFinish.c	(revision 27906)
+++ trunk/ppStack/src/ppStackFinish.c	(revision 30620)
@@ -1,15 +1,5 @@
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "ppStack.h"
 
-#include <stdio.h>
-#include <unistd.h>
-#include <pslib.h>
-#include <psmodules.h>
-#include <psphot.h>
-
-#include "ppStack.h"
-#include "ppStackLoop.h"
-
+// this function unlinks the temporary files (if desired)
 bool ppStackFinish(ppStackOptions *options, pmConfig *config)
 {
@@ -32,10 +22,8 @@
             }
 
-            psString imageResolved = pmConfigConvertFilename(options->convImages->data[i],
-                                                             config, false, false);
-            psString maskResolved = pmConfigConvertFilename(options->convMasks->data[i],
-                                                            config, false, false);
-            psString varianceResolved = pmConfigConvertFilename(options->convVariances->data[i],
-                                                                config, false, false);
+	    // XXX careful about repeatative resolution of nebulous names (though these are probably not neb names)
+            psString imageResolved = pmConfigConvertFilename(options->convImages->data[i], config, false, false);
+            psString maskResolved = pmConfigConvertFilename(options->convMasks->data[i], config, false, false);
+            psString varianceResolved = pmConfigConvertFilename(options->convVariances->data[i], config, false, false);
             if (unlink(imageResolved) == -1 || unlink(maskResolved) == -1 ||
                 unlink(varianceResolved) == -1) {
@@ -47,6 +35,4 @@
         }
     }
-
-
     return true;
 }
@@ -60,54 +46,56 @@
 
     psErrorCode errorCode = psErrorCodeLast(); // Error code
-    if (errorCode != PS_ERR_NONE) {
-        psErrorStackPrint(stderr, "Unable to perform stack.");
-        pmFPAfileFreeSetStrict(false);
-        switch (errorCode) {
-          case PPSTACK_ERR_UNKNOWN:
-          case PS_ERR_UNKNOWN:
-            psLogMsg("ppStack", PS_LOG_WARN, "Unknown error code: %x", errorCode);
-            exitValue = PS_EXIT_UNKNOWN_ERROR;
-            break;
-          case PS_ERR_IO:
-          case PS_ERR_DB_CLIENT:
-          case PS_ERR_DB_SERVER:
-          case PS_ERR_BAD_FITS:
-          case PS_ERR_OS_CALL_FAILED:
-          case PM_ERR_SYS:
-          case PPSTACK_ERR_IO:
-            psLogMsg("ppStack", PS_LOG_WARN, "I/O error code: %x", errorCode);
-            exitValue = PS_EXIT_SYS_ERROR;
-            break;
-          case PS_ERR_BAD_PARAMETER_VALUE:
-          case PS_ERR_BAD_PARAMETER_TYPE:
-          case PS_ERR_BAD_PARAMETER_NULL:
-          case PS_ERR_BAD_PARAMETER_SIZE:
-          case PPSTACK_ERR_ARGUMENTS:
-          case PPSTACK_ERR_CONFIG:
-            psLogMsg("ppStack", PS_LOG_WARN, "Configuration error code: %x", errorCode);
-            exitValue = PS_EXIT_CONFIG_ERROR;
-            break;
-          case PPSTACK_ERR_PSF:
-          case PSPHOT_ERR_PSF:
-          case PM_ERR_STAMPS:
-          case PM_ERR_SMALL_AREA:
-          case PPSTACK_ERR_REJECTED:
-          case PPSTACK_ERR_DATA:
-            psLogMsg("ppStack", PS_LOG_WARN, "Data error code: %x", errorCode);
-            exitValue = PS_EXIT_DATA_ERROR;
-            break;
-          case PS_ERR_UNEXPECTED_NULL:
-          case PS_ERR_PROGRAMMING:
-          case PPSTACK_ERR_NOT_IMPLEMENTED:
-          case PPSTACK_ERR_PROG:
-            psLogMsg("ppStack", PS_LOG_WARN, "Programming error code: %x", errorCode);
-            exitValue = PS_EXIT_PROG_ERROR;
-            break;
-          default:
-            // It's a programming error if we're not dealing with the error correctly
-            psLogMsg("ppStack", PS_LOG_WARN, "Unrecognised error code: %x", errorCode);
-            exitValue = PS_EXIT_PROG_ERROR;
-            break;
-        }
+    if (errorCode == PS_ERR_NONE) {
+	return exitValue;
+    }
+
+    psErrorStackPrint(stderr, "Unable to perform stack.");
+    pmFPAfileFreeSetStrict(false);
+    switch (errorCode) {
+      case PPSTACK_ERR_UNKNOWN:
+      case PS_ERR_UNKNOWN:
+	psLogMsg("ppStack", PS_LOG_WARN, "Unknown error code: %x", errorCode);
+	exitValue = PS_EXIT_UNKNOWN_ERROR;
+	break;
+      case PS_ERR_IO:
+      case PS_ERR_DB_CLIENT:
+      case PS_ERR_DB_SERVER:
+      case PS_ERR_BAD_FITS:
+      case PS_ERR_OS_CALL_FAILED:
+      case PM_ERR_SYS:
+      case PPSTACK_ERR_IO:
+	psLogMsg("ppStack", PS_LOG_WARN, "I/O error code: %x", errorCode);
+	exitValue = PS_EXIT_SYS_ERROR;
+	break;
+      case PS_ERR_BAD_PARAMETER_VALUE:
+      case PS_ERR_BAD_PARAMETER_TYPE:
+      case PS_ERR_BAD_PARAMETER_NULL:
+      case PS_ERR_BAD_PARAMETER_SIZE:
+      case PPSTACK_ERR_ARGUMENTS:
+      case PPSTACK_ERR_CONFIG:
+	psLogMsg("ppStack", PS_LOG_WARN, "Configuration error code: %x", errorCode);
+	exitValue = PS_EXIT_CONFIG_ERROR;
+	break;
+      case PPSTACK_ERR_PSF:
+      case PSPHOT_ERR_PSF:
+      case PM_ERR_STAMPS:
+      case PM_ERR_SMALL_AREA:
+      case PPSTACK_ERR_REJECTED:
+      case PPSTACK_ERR_DATA:
+	psLogMsg("ppStack", PS_LOG_WARN, "Data error code: %x", errorCode);
+	exitValue = PS_EXIT_DATA_ERROR;
+	break;
+      case PS_ERR_UNEXPECTED_NULL:
+      case PS_ERR_PROGRAMMING:
+      case PPSTACK_ERR_NOT_IMPLEMENTED:
+      case PPSTACK_ERR_PROG:
+	psLogMsg("ppStack", PS_LOG_WARN, "Programming error code: %x", errorCode);
+	exitValue = PS_EXIT_PROG_ERROR;
+	break;
+      default:
+	// It's a programming error if we're not dealing with the error correctly
+	psLogMsg("ppStack", PS_LOG_WARN, "Unrecognised error code: %x", errorCode);
+	exitValue = PS_EXIT_PROG_ERROR;
+	break;
     }
     return exitValue;
