Index: /branches/eam_branches/ohana.20160226/src/relastro/include/relastro.h
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/include/relastro.h	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/include/relastro.h	(revision 39442)
@@ -417,6 +417,6 @@
 int SetSignals (void);
 
-void relastro_client_free ();
-void relastro_free ();
+void relastro_free (SkyTable *sky, SkyList *skylist);
+void relastro_client_free (SkyTable *sky, SkyList *skylist);
 
 GSCRegion    *find_regions        PROTO((Image *image, off_t Nimage, int *Nregions, GSCRegion *fullregion));
@@ -660,4 +660,5 @@
 int indexCatalogs (Catalog *catalog, int Ncatalog);
 int catID_and_objID_to_seq (unsigned int catID, unsigned int objID, int *catSeq, off_t *objSeq);
+void freeCatalogIndexes (int Ncatalog);
 
 int markObjects (Catalog *catalog, int Ncatalog);
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/ImageOps.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/ImageOps.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/ImageOps.c	(revision 39442)
@@ -9,16 +9,16 @@
 // if we read only a subset of the rows from the Image FITS, LineNumber tells us to which row
 // each image belongs
-static off_t       *LineNumber; // match of subset to full image table
-
-static off_t        *N_onImage;   // number of measurements on image
-static off_t        *N_ONIMAGE;   // allocated number of measurements on image   
-
-static int          *Ncatlist;  // catalogs associated with each image
-static int          *NCATLIST;  // catalogs associated with each image
-static int         **catlist;  // catalogs associated with each image
-
-static IDX_T       **MeasureToImage;     // link from catalog,measure to image
-static IDX_T       **ImageToCatalog;   // catalog which supplied measurement on image
-static IDX_T       **ImageToMeasure;   // measure reference for measurement on image
+static off_t       *LineNumber = NULL; // match of subset to full image table
+
+static off_t        *N_onImage = NULL;   // number of measurements on image
+static off_t        *N_ONIMAGE = NULL;   // allocated number of measurements on image   
+
+static int          *Ncatlist = NULL;  // catalogs associated with each image
+static int          *NCATLIST = NULL;  // catalogs associated with each image
+static int         **catlist  = NULL;  // catalogs associated with each image
+
+static IDX_T       **MeasureToImage = NULL;     // link from catalog,measure to image
+static IDX_T       **ImageToCatalog = NULL;   // catalog which supplied measurement on image
+static IDX_T       **ImageToMeasure = NULL;   // measure reference for measurement on image
 
 // if we search by image ID, we sort (imageIDs, imageIdx) by imageIDs to get a sorted
@@ -26,9 +26,9 @@
 
 # if USE_IMAGE_ID
-static off_t        *imageIDs; // list of all image IDs
-static off_t        *imageIdx; // list of index for image IDs 
+static off_t        *imageIDs = NULL; // list of all image IDs
+static off_t        *imageIdx = NULL; // list of index for image IDs 
 
 // as an alternative, we generate imageSeq, which directly maps imageID -> seq
-static off_t        *imageSeq; // list of index for image IDs 
+static off_t        *imageSeq = NULL; // list of index for image IDs 
 
 // MAX_ID requires 512M to store the image index
@@ -218,9 +218,12 @@
     FREE (ImageToCatalog[i]); 
     FREE (ImageToMeasure[i]); 
-    FREE (catlist[i]); 
+    if (catlist) { FREE (catlist[i]); }
   }
   FREE (Ncatlist);
   FREE (NCATLIST);
   FREE (catlist);
+  Ncatlist = NULL;
+  NCATLIST = NULL;
+  catlist  = NULL;
 
   FREE (ImageToCatalog);
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/UpdateObjectOffsets.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/UpdateObjectOffsets.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/UpdateObjectOffsets.c	(revision 39442)
@@ -62,5 +62,5 @@
     // uses MeasureTiny values, but will also update Measure values when populated
     // if Galaxy Motion Model correction is active, do not apply at this last stage 
-    UpdateObjects (&catalog, 1, FALSE);
+    UpdateObjects (&catalog, 1, -1);
 
     free_tiny_values(&catalog);
@@ -218,5 +218,8 @@
     fprintf (stderr, "command: %s\n", command);
 
-    if (PARALLEL_MANUAL) continue;
+    if (PARALLEL_MANUAL) {
+      free (command);
+      continue;
+    }
 
     if (PARALLEL_SERIAL) {
@@ -236,4 +239,5 @@
       group->hosts[i][0].pid = pid; // save for future reference
     }
+    free (command);
   }
 
@@ -338,5 +342,8 @@
     fprintf (stderr, "command: %s\n", command);
 
-    if (PARALLEL_MANUAL) continue;
+    if (PARALLEL_MANUAL) {
+      free (command);
+      continue;
+    }
 
     if (PARALLEL_SERIAL) {
@@ -356,4 +363,5 @@
       table->hosts[i].pid = pid; // save for future reference
     }
+    free (command);
   }
 
@@ -366,4 +374,6 @@
   }
 
+  FreeHostTable (table);
+
   return TRUE;
 }      
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/args.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/args.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/args.c	(revision 39442)
@@ -572,5 +572,5 @@
 }
 
-void relastro_free () {
+void relastro_free (SkyTable *sky, SkyList *skylist) {
   FREE (REGION_FILE);
   FREE (IMAGE_TABLE);
@@ -591,4 +591,18 @@
   FREE (BCATALOG);
   FREE (HOSTDIR);
+
+  // these are set in initialize
+  FREE(photcodesKeep);
+  FREE(photcodesSkip);  
+  FREE(photcodesReset); 
+  FREE(photcodesGroupA);
+  FREE(photcodesGroupB);
+  
+  SkyTableFree (sky);
+  SkyListFree(skylist);
+  FreePhotcodeTable();
+  
+  ohana_memcheck (VERBOSE);
+  ohana_memdump (VERBOSE);
 }
 
@@ -951,5 +965,5 @@
 }
 
-void relastro_client_free () {
+void relastro_client_free (SkyTable *sky, SkyList *skylist) {
   FREE (PHOTCODE_SKIP_LIST);
   FREE (PHOTCODE_KEEP_LIST);
@@ -965,4 +979,18 @@
   FREE(BCATALOG);
   FREE (HOSTDIR);
+
+  // these are set in initialize
+  FREE(photcodesKeep);
+  FREE(photcodesSkip);  
+  FREE(photcodesReset); 
+  FREE(photcodesGroupA);
+  FREE(photcodesGroupB);
+  
+  SkyTableFree (sky);
+  SkyListFree(skylist);
+  FreePhotcodeTable();
+  
+  ohana_memcheck (VERBOSE);
+  ohana_memdump (VERBOSE);
 }
 
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/indexCatalogs.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/indexCatalogs.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/indexCatalogs.c	(revision 39442)
@@ -51,4 +51,15 @@
 }
 
+void freeCatalogIndexes (int Ncatalog) {
+  int i;
+
+  for (i = 0; i < Ncatalog; i++) {
+    free (objIDseq[i]);
+  }
+  free (objIDmax);
+  free (objIDseq);
+  free (catIDseq);
+}
+
 int catID_and_objID_to_seq (unsigned int catID, unsigned int objID, int *catSeq, off_t *objSeq) {
 
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/initialize.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/initialize.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/initialize.c	(revision 39442)
@@ -2,4 +2,10 @@
 
 void initialize (int argc, char **argv) {
+
+  photcodesKeep   = NULL; 
+  photcodesSkip   = NULL; 
+  photcodesReset  = NULL; 
+  photcodesGroupA = NULL; 
+  photcodesGroupB = NULL; 
 
   ConfigInit (&argc, argv);
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro.c	(revision 39442)
@@ -20,43 +20,15 @@
       /* the object analysis is a separate process iterating over catalogs */
       relastro_objects (skylist, 0, NULL);
-      ohana_memcheck (VERBOSE);
-      ohana_memdump (VERBOSE);
-      exit (0);
-
-    case OP_HIGH_SPEED:
-      /* high-speed is a 2pt cross-correlation process for linking moving objects (high PM) */
-      high_speed_catalogs (sky, skylist, 0, NULL);
-      exit (0);
-
-    case OP_HPM:
-      hpm_catalogs (sky, skylist, 0, NULL);
-      exit (0);
-
-    case OP_MERGE_SOURCE:
-      /* a special method to manually merge unlinked detections of sources togther (not parallel) */
-      relastro_merge_source (sky);
+      relastro_free (sky, skylist);
       exit (0);
 
     case OP_IMAGES:
       relastro_images (skylist);
-
-      relastro_free ();
-      FREE(photcodesKeep);
-      FREE(photcodesSkip);  
-      FREE(photcodesReset); 
-      FREE(photcodesGroupA);
-      FREE(photcodesGroupB);
-
-      SkyTableFree (sky);
-      SkyListFree(skylist);
-      FreePhotcodeTable();
-
-      ohana_memcheck (VERBOSE);
-      ohana_memdump (VERBOSE);
+      relastro_free (sky, skylist);
       exit (0);
 
-    case OP_UPDATE_OFFSETS: 
+    case OP_UPDATE_OFFSETS: {
+      FITS_DB db;
       if (!PARALLEL) {
-	FITS_DB db;
       
 	set_db (&db);
@@ -76,7 +48,14 @@
       // iterate over catalogs to make detection coordinates consistant
       UpdateObjectOffsets (skylist, 0, NULL);
-      ohana_memcheck (VERBOSE);
-      ohana_memdump (VERBOSE);
+
+      if (!PARALLEL) {
+	gfits_db_free (&db);
+	freeImages();
+	freeMosaics ();
+      }	
+
+      relastro_free (sky, skylist);
       exit (0);
+    }
 
     case OP_PARALLEL_REGIONS:
@@ -90,4 +69,18 @@
       exit (0);
 
+    case OP_HIGH_SPEED:
+      /* high-speed is a 2pt cross-correlation process for linking moving objects (high PM) */
+      high_speed_catalogs (sky, skylist, 0, NULL);
+      exit (0);
+
+    case OP_HPM:
+      hpm_catalogs (sky, skylist, 0, NULL);
+      exit (0);
+
+    case OP_MERGE_SOURCE:
+      /* a special method to manually merge unlinked detections of sources togther (not parallel) */
+      relastro_merge_source (sky);
+      exit (0);
+
     default:
       fprintf (stderr, "impossible!\n");
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_client.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_client.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_client.c	(revision 39442)
@@ -55,8 +55,4 @@
       }
 
-      SkyTableFree (sky);
-      SkyListFree(skylist);
-      FreePhotcodeTable();
-
       int i;
       for (i = 0; i < Ncatalog; i++) {
@@ -66,13 +62,5 @@
       BrightCatalogFree(bcatalog);
 
-      relastro_client_free ();
-      FREE(photcodesKeep);
-      FREE(photcodesSkip);  
-      FREE(photcodesReset); 
-      FREE(photcodesGroupA);
-      FREE(photcodesGroupB);
-
-      ohana_memcheck (TRUE);
-      ohana_memdump (TRUE);
+      relastro_client_free (sky, skylist);
       break;
     }
@@ -81,16 +69,5 @@
       // USAGE: relastro_client -update-objects
       relastro_objects (skylist, HOST_ID, HOSTDIR);
-      break;
-    }
-
-    case OP_HIGH_SPEED: {
-      // USAGE: relastro_client -high-speed
-      high_speed_catalogs (sky, skylist, HOST_ID, HOSTDIR);
-      break;
-    }
-
-    case OP_HPM: {
-      // USAGE: relastro_client -high-speed
-      hpm_catalogs (sky, skylist, HOST_ID, HOSTDIR);
+      relastro_client_free (sky, skylist);
       break;
     }
@@ -112,25 +89,24 @@
       /* load regions and images based on specified sky patch (default depth) */
       load_images (&db, skylist, FALSE, USE_ALL_IMAGES);
-      
-      // I can free the database after I have loaded the images...
-
-      // // load the image subset table from the specified location
-      // off_t Nimage;
-      // ImageSubset *image = ImageSubsetLoad (IMAGES, &Nimage);
-      // if (!image) {
-      // 	  fprintf (stderr, "ERROR loading image subset %s\n", CATDIR);
-      // 	  exit (2);
-      // }
-      // 
-      // // save the available image information in the static array in ImageOps.c
-      // initImagesSubset (image, NULL, Nimage);
-      // 
-      // // load the flat-field correction table from CATDIR
-      // char flatcorrFile[1024];
-      // snprintf (flatcorrFile, 1024, "%s/flatcorr.fits", CATDIR);
-      // FlatCorrectionTable *flatcorr = FlatCorrectionLoad (flatcorrFile, VERBOSE);
 
       UpdateObjectOffsets (skylist, HOST_ID, HOSTDIR);
       
+      gfits_db_free (&db);
+      freeImages();
+      freeMosaics ();
+
+      relastro_client_free (sky, skylist);
+      break;
+    }
+
+    case OP_HIGH_SPEED: {
+      // USAGE: relastro_client -high-speed
+      high_speed_catalogs (sky, skylist, HOST_ID, HOSTDIR);
+      break;
+    }
+
+    case OP_HPM: {
+      // USAGE: relastro_client -high-speed
+      hpm_catalogs (sky, skylist, HOST_ID, HOSTDIR);
       break;
     }
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_objects.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_objects.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_objects.c	(revision 39442)
@@ -84,5 +84,7 @@
     populate_tiny_values(&catalog, DVO_TV_MEASURE);
 
-    UpdateObjects (&catalog, 1, 0);
+    // the 3rd argument (-1) is the loop number for re-weighting 2MASS and Tycho. -1 is a special value meaning "ignore" 
+    // we do NOT want to apply special weights to 2MASS and/or Tycho when calculating object final motions.
+    UpdateObjects (&catalog, 1, -1); 
 
     free_tiny_values(&catalog);
@@ -215,4 +217,5 @@
       table->hosts[i].pid = pid; // save for future reference
     }
+    free (command);
   }
 
@@ -224,4 +227,5 @@
     HostTableWaitJobsGetIO (table, __FILE__, __LINE__, VERBOSE);
   }
+  FreeHostTable (table);
 
   return TRUE;
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_images.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_images.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_images.c	(revision 39442)
@@ -16,4 +16,8 @@
 
   INITTIME;
+
+  // over-ride user selection here: this program does not set the final object 
+  // astrometry.  since it only sets the image parameters it should not use pm or par
+  FIT_MODE = FIT_AVERAGE;
 
   client_logger_init (CATDIR);
@@ -187,4 +191,6 @@
   }
   free (catalog);
+  freeCatalogIndexes(Ncatalog);
+
   freeMosaics ();
 
@@ -194,19 +200,7 @@
   free (image);
 
-  relastro_free ();
-  FREE(photcodesKeep);
-  FREE(photcodesSkip);  
-  FREE(photcodesReset); 
-  FREE(photcodesGroupA);
-  FREE(photcodesGroupB);
-  
-  SkyTableFree (sky);
-  SkyListFree(skylist);
-  FreePhotcodeTable();
-  
   FreeRegionHostTable (regionHosts);
-
-  ohana_memcheck (VERBOSE);
-  ohana_memdump (VERBOSE);
+  relastro_free (sky, skylist);
+
   exit (0);
 }
Index: /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_regions.c
===================================================================
--- /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_regions.c	(revision 39441)
+++ /branches/eam_branches/ohana.20160226/src/relastro/src/relastro_parallel_regions.c	(revision 39442)
@@ -91,19 +91,6 @@
   freeMosaics ();
 
-  relastro_free ();
-  FREE(photcodesKeep);
-  FREE(photcodesSkip);  
-  FREE(photcodesReset); 
-  FREE(photcodesGroupA);
-  FREE(photcodesGroupB);
-  
-  SkyTableFree (sky);
-  SkyListFree(skylist);
-  FreePhotcodeTable();
-  
   FreeRegionHostTable (regionHosts);
-
-  ohana_memcheck (VERBOSE);
-  ohana_memdump (VERBOSE);
+  relastro_free (sky, skylist);
 
   exit (0);
