Index: branches/eam_branches/gDiff.20200202/src/gDiff.c
===================================================================
--- branches/eam_branches/gDiff.20200202/src/gDiff.c	(revision 41260)
+++ branches/eam_branches/gDiff.20200202/src/gDiff.c	(revision 41413)
@@ -18,4 +18,6 @@
     psphotErrorRegister();
 
+    psExit exitValue = PS_EXIT_SUCCESS; // default value
+
     gDiffData *data = NULL; // Processing data
     pmConfig *config = pmConfigRead(&argc, argv, GDIFF_RECIPE); // Configuration
@@ -26,6 +28,8 @@
     psphotInit(); // cannot return false
 
+    // the 'data' container carries pointers to all data structures used by gDiff
     data = gDiffDataAlloc(config);
 
+    // parse the command-line options
     if (!gDiffArguments(argc, argv, data)) {
         psError(psErrorCodeLast(), false, "Error reading arguments.");
@@ -33,5 +37,5 @@
     }
 
-    // determine the camera and setup the I/O file handles
+    // determine the camera and setup the (many) I/O file handles
     if (!gDiffCamera(data)) goto die;
 
@@ -40,54 +44,52 @@
 
  die:
-    {
-        psExit exitValue = gDiffExitCode(PS_EXIT_SUCCESS); // Exit code
+    exitValue = gDiffExitCode(exitValue); // Exit code
 
-        if (data && data->stats && data->statsFile) {
-  	    psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_DIFF", 0, "Total time (sec)", psTimerMark("gDiff"));
-            psString stats = psMetadataConfigFormat(data->stats); // Statistics to output
-            if (!stats || strlen(stats) == 0) {
-                psError(GDIFF_ERR_IO, false, "Unable to format statistics file");
-            } else if (fprintf(data->statsFile, "%s", stats) != strlen(stats)) {
-                psError(GDIFF_ERR_IO, true, "Unable to write statistics file");
-            }
-            psFree(stats);
-            if (fclose(data->statsFile) == EOF) {
-                psError(GDIFF_ERR_IO, true, "Unable to close statistics file");
-            }
-            data->statsFile = NULL;
-            pmConfigRunFilenameAddWrite(data->config, "STATS", data->statsName);
-            exitValue = gDiffExitCode(exitValue);
-        }
+    if (data && data->stats && data->statsFile) {
+      psMetadataAddF32(data->stats, PS_LIST_TAIL, "TIME_DIFF", 0, "Total time (sec)", psTimerMark("gDiff"));
+      psString stats = psMetadataConfigFormat(data->stats); // Statistics to output
+      if (!stats || strlen(stats) == 0) {
+	psError(GDIFF_ERR_IO, false, "Unable to format statistics file");
+      } else if (fprintf(data->statsFile, "%s", stats) != strlen(stats)) {
+	psError(GDIFF_ERR_IO, true, "Unable to write statistics file");
+      }
+      psFree(stats);
+      if (fclose(data->statsFile) == EOF) {
+	psError(GDIFF_ERR_IO, true, "Unable to close statistics file");
+      }
+      data->statsFile = NULL;
+      pmConfigRunFilenameAddWrite(data->config, "STATS", data->statsName);
+      exitValue = gDiffExitCode(exitValue);
+    }
 
-        if (config && !gDiffFilesIterateUp(config, GDIFF_FILES_ALL)) {
-            psError(psErrorCodeLast(), false, "Unable to close files.");
-            exitValue = gDiffExitCode(exitValue);
-            pmFPAfileFreeSetStrict(false);
-        }
+    if (config && !gDiffFilesIterateUp(config, GDIFF_FILES_ALL)) {
+      psError(psErrorCodeLast(), false, "Unable to close files.");
+      exitValue = gDiffExitCode(exitValue);
+      pmFPAfileFreeSetStrict(false);
+    }
 
-        if (data) {
-            psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "DUMP_CONFIG");
-            if (dump_file) {
-                if (!pmConfigDump(data->config, dump_file)) {
-                    psError(GDIFF_ERR_IO, false, "Unable to dump configuration.");
-                    exitValue = gDiffExitCode(exitValue);
-                }
-            }
-            psFree(data);
-        }
+    if (data) {
+      psString dump_file = psMetadataLookupStr(NULL, data->config->arguments, "DUMP_CONFIG");
+      if (dump_file) {
+	if (!pmConfigDump(data->config, dump_file)) {
+	  psError(GDIFF_ERR_IO, false, "Unable to dump configuration.");
+	  exitValue = gDiffExitCode(exitValue);
+	}
+      }
+      psFree(data);
+    }
 
-        psTrace("gDiff", 1, "Finished at %f sec\n", psTimerMark("gDiff"));
-	psLogMsg("gDiff", PS_LOG_INFO, "Complete gDiff run: %f sec\n", psTimerMark("gDiff"));
-        psTimerStop();
+    psTrace("gDiff", 1, "Finished at %f sec\n", psTimerMark("gDiff"));
+    psLogMsg("gDiff", PS_LOG_INFO, "Complete gDiff run: %f sec\n", psTimerMark("gDiff"));
+    psTimerStop();
 
-        pmVisualClose(); // close plot windows, if -visual is set
-        pmModelClassCleanup();
-        pmConfigDone();
-	pmVisualCleanup ();
-        psLibFinalize();
+    pmVisualClose(); // close plot windows, if -visual is set
+    pmModelClassCleanup();
+    pmConfigDone();
+    pmVisualCleanup ();
+    psLibFinalize();
 
-	fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "gDiff");
-        exitValue = gDiffExitCode(exitValue);
-        exit(exitValue);
-    }
+    fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "gDiff");
+    exitValue = gDiffExitCode(exitValue);
+    exit(exitValue);
 }
