Index: trunk/psastro/src/psastro.c
===================================================================
--- trunk/psastro/src/psastro.c	(revision 9587)
+++ trunk/psastro/src/psastro.c	(revision 9627)
@@ -2,5 +2,5 @@
 
 static void usage (void) {
-    psErrorStackPrint(stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)");
+    psErrorStackPrint(stderr, "USAGE: psastro [-file image(s)] [-list imagelist] (output)\n");
     exit (2);
 }
@@ -20,5 +20,5 @@
     // load identify the data sources
     if (!psastroParseCamera (config)) {
-	psErrorStackPrint(stderr, "error setting up the camera");
+	psErrorStackPrint(stderr, "error setting up the camera\n");
 	exit (1);
     }
@@ -27,5 +27,5 @@
     // select subset of stars for astrometry
     if (!psastroDataLoad (config)) {
-	psErrorStackPrint(stderr, "error loading input data");
+	psErrorStackPrint(stderr, "error loading input data\n");
 	exit (1);
     }
@@ -34,5 +34,5 @@
     // apply the initial guess
     if (!psastroAstromGuess (config)) {
-	psErrorStackPrint(stderr, "failed to determine initial astrometry guess");
+	psErrorStackPrint(stderr, "failed to determine initial astrometry guess\n");
 	exit (1);
     }
@@ -41,11 +41,11 @@
     psArray *refs = psastroLoadRefstars (config);
     if (!refs) {
-	psErrorStackPrint(stderr, "failed to load reference data");
+	psErrorStackPrint(stderr, "failed to load reference data\n");
 	exit (1);
     }
 
     // choose reference stars corresponding to the selected chips
-    if (psastroChooseRefstars (config, refs)) {
-	psErrorStackPrint(stderr, "failed to select reference data for chips");
+    if (!psastroChooseRefstars (config, refs)) {
+	psErrorStackPrint(stderr, "failed to select reference data for chips\n");
 	exit (1);
     }
@@ -54,10 +54,10 @@
     if (mosastro == NULL) {
         if (!psastroChipAstrom (config, refs)) {
-	    psErrorStackPrint(stderr, "failed to perform single chip astrometry");
+	    psErrorStackPrint(stderr, "failed to perform single chip astrometry\n");
 	    exit (1);
 	}
     } else {
 	if (!psastroMosaicAstrom (config, refs)) {
-	    psErrorStackPrint(stderr, "failed to perform mosaic camera astrometry");
+	    psErrorStackPrint(stderr, "failed to perform mosaic camera astrometry\n");
 	    exit (1);
 	}
@@ -69,5 +69,5 @@
     // write out the results
     if (!psastroDataSave (config)) {
-	psErrorStackPrint(stderr, "failed to write out data");
+	psErrorStackPrint(stderr, "failed to write out data\n");
 	exit (1);
     }
@@ -75,16 +75,5 @@
     psLogMsg ("psastro", 3, "complete psastro run: %f sec\n", psTimerMark ("complete"));
 
-    psFree (refs);
-    psFree (config);
-
-    psTimerStop ();
-    psMemCheckCorruption (true);
-    pmModelGroupCleanup ();
-    psTimeFinalize ();
-    pmConceptsDone ();
-    pmConfigDone ();
-    // fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, stdout, false), "psastro");
-    fprintf (stderr, "found %d leaks at %s\n", psMemCheckLeaks (0, NULL, NULL, false), "psastro");
-
-    exit (0);
+    psastroCleanup (config, refs);
+    exit (EXIT_SUCCESS);
 }
