Index: /trunk/psModules/src/objects/pmSourceMatch.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceMatch.c	(revision 23240)
+++ /trunk/psModules/src/objects/pmSourceMatch.c	(revision 23241)
@@ -16,5 +16,5 @@
 #define SOURCE_FAINTEST 50.0            // Faintest magnitude to consider
 #define SOURCES_MAX_LEAF 2              // Maximum number of points on a tree leaf
-
+#define ARRAY_BUFFER 16                 // Buffer for array
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -113,6 +113,5 @@
 }
 
-pmSourceMatch *pmSourceMatchAlloc(int num // Maximum number of images
-    )
+pmSourceMatch *pmSourceMatchAlloc(void)
 {
     pmSourceMatch *match = psAlloc(sizeof(pmSourceMatch)); // Match data
@@ -120,9 +119,9 @@
 
     match->num = 0;
-    match->mag = psVectorAllocEmpty(num, PS_TYPE_F32);
-    match->magErr = psVectorAllocEmpty(num, PS_TYPE_F32);
-    match->image = psVectorAllocEmpty(num, PS_TYPE_U32);
-    match->index = psVectorAllocEmpty(num, PS_TYPE_U32);
-    match->mask = psVectorAllocEmpty(num, PS_TYPE_VECTOR_MASK);
+    match->mag = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_F32);
+    match->magErr = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_F32);
+    match->image = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_U32);
+    match->index = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_U32);
+    match->mask = psVectorAllocEmpty(ARRAY_BUFFER, PS_TYPE_VECTOR_MASK);
 
     return match;
@@ -136,8 +135,10 @@
 {
     int num = match->num;               // Number of matches
-    psAssert(num <= match->mag->nalloc, "Too many matches.");
-    psAssert(num <= match->magErr->nalloc, "Too many matches.");
-    psAssert(num <= match->image->nalloc, "Too many matches.");
-    psAssert(num <= match->index->nalloc, "Too many matches.");
+
+    match->mag = psVectorExtend(match->mag, match->mag->nalloc, 1);
+    match->magErr = psVectorExtend(match->magErr, match->magErr->nalloc, 1);
+    match->image = psVectorExtend(match->image, match->image->nalloc, 1);
+    match->index = psVectorExtend(match->index, match->index->nalloc, 1);
+    match->mask = psVectorExtend(match->mask, match->mask->nalloc, 1);
 
     match->mag->data.F32[num] = mag;
@@ -148,5 +149,5 @@
     match->num++;
 
-    match->mag->n = match->magErr->n = match->image->n = match->index->n = match->mask->n = match->num;
+    return;
 }
 
@@ -185,16 +186,13 @@
             matches = psArrayAlloc(numSources);
             for (int j = 0; j < numSources; j++) {
-                pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
+                pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
                 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
                 matches->data[j] = match;
             }
             numMaster += numSources;
-            goto match_image_done;
-        }
-
-        if (boundsImage->x0 > boundsMaster->x1 || boundsImage->x1 < boundsMaster->x0 ||
-            boundsImage->y0 > boundsMaster->y1 || boundsImage->y1 < boundsMaster->y0) {
+        } else if (boundsImage->x0 > boundsMaster->x1 || boundsImage->x1 < boundsMaster->x0 ||
+                   boundsImage->y0 > boundsMaster->y1 || boundsImage->y1 < boundsMaster->y0) {
+            // Bounds don't overlap --- can just add everything in to the master list
             psTrace("psModules.objects", 7, "Bounds don't overlap\n");
-            // Add everything in to the master list
             long size = numMaster + numSources; // New size
             xMaster = psVectorRealloc(xMaster, size);
@@ -207,5 +205,5 @@
                    numSources * PSELEMTYPE_SIZEOF(PS_TYPE_F32));
             for (int j = 0, k = numMaster; j < numSources; j++, k++) {
-                pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
+                pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
                 pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
                 matches->data[k] = match;
@@ -215,12 +213,8 @@
             yMaster->n = size;
             matches->n = size;
-
-            goto match_image_done;
-        }
-
-        // Match with the master list
-        {
+        } else {
+            // Match with the master list
             psTree *tree = psTreePlant(2, SOURCES_MAX_LEAF, xMaster, yMaster); // kd Tree with sources
-            long numMatch = 0;              // Number of matches
+            long numMatch = 0;          // Number of matches
 
             long size = numMaster + numSources; // New size
@@ -241,5 +235,5 @@
                 } else {
                     // Add to the master list
-                    pmSourceMatch *match = pmSourceMatchAlloc(numImages); // Match data
+                    pmSourceMatch *match = pmSourceMatchAlloc(); // Match data
                     pmSourceMatchAdd(match, magImage->data.F32[j], magErrImage->data.F32[j], i, j);
                     xMaster->data.F32[numMaster] = xImage->data.F32[j];
@@ -255,5 +249,4 @@
         }
 
-    match_image_done:
         psFree(boundsImage);
         psFree(xImage);
@@ -306,8 +299,8 @@
                 continue;
             }
-            int image = match->image->data.S32[j]; // Index of image
-            int index = match->index->data.S32[j]; // Index of source for image
-            psArray *list = sourceArrays->data[image]; // List of interest
-            source = list->data[index];
+            int imgIndex = match->image->data.S32[j]; // Index of image
+            int srcIndex = match->index->data.S32[j]; // Index of source for image
+            psArray *list = sourceArrays->data[imgIndex]; // List of interest
+            source = list->data[srcIndex];
             break;
         }
Index: /trunk/psModules/src/objects/pmSourceMatch.h
===================================================================
--- /trunk/psModules/src/objects/pmSourceMatch.h	(revision 23240)
+++ /trunk/psModules/src/objects/pmSourceMatch.h	(revision 23241)
@@ -33,6 +33,5 @@
 
 /// Allocator for pmSourceMatch
-pmSourceMatch *pmSourceMatchAlloc(int num // Maximum number of images
-                                  );
+pmSourceMatch *pmSourceMatchAlloc(void);
 
 /// Add a source to a match
