Index: /trunk/psphot/src/pmFootprint.c
===================================================================
--- /trunk/psphot/src/pmFootprint.c	(revision 13371)
+++ /trunk/psphot/src/pmFootprint.c	(revision 13372)
@@ -893,13 +893,13 @@
     }
 
-    psImage *grownIdImage = psImageConvolveDirect(idImage, circle);
+    psImage *grownIdImage = psImageConvolveDirect(idImage, circle); // Here's the actual grow step
     psFree(circle);	
 
-    psArray *grown = pmFindFootprints(grownIdImage, 0.5, 1);
+    psArray *grown = pmFindFootprints(grownIdImage, 0.5, 1); // and here we rebuild the grown footprints
     assert (grown != NULL);
     psFree(idImage); psFree(grownIdImage);
     /*
      * Now assign the peaks appropriately.  We could do this more efficiently
-     * using idImage (which we just freed), but this is easy and probably fast enough
+     * using grownIdImage (which we just freed), but this is easy and probably fast enough
      */
     const psArray *peaks = pmFootprintArrayToPeaks(footprints);
@@ -918,6 +918,7 @@
  * their reference counters suitable incremented)
  */
-psArray *pmMergeFootprintArrays(const psArray *footprints1,
-				const psArray *footprints2) {
+psArray *pmMergeFootprintArrays(const psArray *footprints1, // one set of footprints
+				const psArray *footprints2, // the other set
+				const int includePeaks) { // which peaks to set? 0x1 => footprints1, 0x2 => 2
     assert (footprints1->n == 0 || pmIsFootprint(footprints1->data[0]));
     assert (footprints2->n == 0 || pmIsFootprint(footprints2->data[0]));
@@ -962,15 +963,17 @@
      * Now assign the peaks appropriately.  We could do this more efficiently
      * using idImage (which we just freed), but this is easy and probably fast enough
-     */
-    const psArray *peaks;
+     */ 
+    if (includePeaks & 0x1) {
+	const psArray *peaks = pmFootprintArrayToPeaks(footprints1);
+	pmPeaksAssignToFootprints(merged, peaks);
+	psFree((psArray *)peaks);
+    }
+
+    if (includePeaks & 0x2) {
+	const psArray *peaks = pmFootprintArrayToPeaks(footprints2);
+	pmPeaksAssignToFootprints(merged, peaks);
+	psFree((psArray *)peaks);
+    }
     
-    peaks = pmFootprintArrayToPeaks(footprints1);
-    pmPeaksAssignToFootprints(merged, peaks);
-    psFree((psArray *)peaks);
-
-    peaks = pmFootprintArrayToPeaks(footprints2);
-    pmPeaksAssignToFootprints(merged, peaks);
-    psFree((psArray *)peaks);
-
     return merged;
 }
@@ -1031,9 +1034,16 @@
     psFree(ids);
     //
-    // Make sure that peaks within each footprint are sorted
+    // Make sure that peaks within each footprint are sorted and unique
     //
     for (int i = 0; i < footprints->n; i++) {
 	pmFootprint *fp = footprints->data[i];
         fp->peaks = psArraySort(fp->peaks, pmPeakSortBySN);
+
+	for (int j = 1; j < fp->peaks->n; j++) { // check for duplicates
+	    if (fp->peaks->data[j] == fp->peaks->data[j-1]) {
+		(void)psArrayRemoveIndex(fp->peaks, j);
+		j--;			// we moved everything down one
+	    }
+	}
     }
 
Index: /trunk/psphot/src/pmFootprint.h
===================================================================
--- /trunk/psphot/src/pmFootprint.h	(revision 13371)
+++ /trunk/psphot/src/pmFootprint.h	(revision 13372)
@@ -36,5 +36,6 @@
 
 psArray *pmGrowFootprintArray(const psArray *footprints, int r);
-psArray *pmMergeFootprintArrays(const psArray *footprints1, const psArray *footprints2);
+psArray *pmMergeFootprintArrays(const psArray *footprints1, const psArray *footprints2,
+                                const int includePeaks);
 
 psImage *pmSetFootprintArrayIDs(const psArray *footprints, const bool relativeIDs);
