Index: /branches/eam_branches/ipp-20140717/Ohana/src/dvomerge/src/build_links.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/dvomerge/src/build_links.c	(revision 37089)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/dvomerge/src/build_links.c	(revision 37090)
@@ -343,6 +343,14 @@
 Lensing *sort_lensing (Average *average, off_t Naverage, Lensing *lensing, off_t Nlensing, off_t *next_lens) {
 
-  off_t i, k, n, N;
+  off_t i, k, n, np, N;
   Lensing *tmplensing;
+
+  /*
+  for (i = 0; i < Naverage; i++) {
+    if (average[i].Nlensing != 4) {
+      fprintf (stderr, "check %d %d %d\n", (int) i, (int) average[i].Nlensing, (int) average[i].lensingOffset);
+    }
+  }
+  */
 
   /* fix order of Lensing (memory intensive, but fast) */
@@ -354,8 +362,12 @@
     average[i].lensingOffset = N;
     for (k = 0; k < average[i].Nlensing; k++, N++) {
-      if (n == -1) abort();
+      if (n == -1) {
+	fprintf (stderr, "entry after %d has a problem\n", (int) np);
+	abort();
+      }
       tmplensing[N] = lensing[n]; 
       if (lensing[n].averef != i) abort();
       tmplensing[N].averef = i;
+      np = n;
       n = next_lens[n];
     }
Index: /branches/eam_branches/ipp-20140717/Ohana/src/dvomerge/src/merge_catalogs_old.c
===================================================================
--- /branches/eam_branches/ipp-20140717/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 37089)
+++ /branches/eam_branches/ipp-20140717/Ohana/src/dvomerge/src/merge_catalogs_old.c	(revision 37090)
@@ -269,4 +269,5 @@
 	output[0].lensing[Nlens].objID    = output[0].average[n].objID;
 	output[0].lensing[Nlens].catID    = output[0].catID;
+	output[0].average[n].Nlensing ++;
 	Nlens ++;
       }
@@ -388,4 +389,5 @@
     /** add lensing for this input average object **/
     if (output[0].lensing) {
+      output[0].average[Nave].lensingOffset  = Nlens;
       for (Nin = 0; Nin < input[0].average[N].Nlensing; Nin ++) {
 	// supply the lensing values from this detection
