diff --git a/gstlal-inspiral/lib/gstlal_snglinspiral.c b/gstlal-inspiral/lib/gstlal_snglinspiral.c
index 21a7d596c2baa7bd3dca843959d5b4b4443533de..9c1123f125958fe43a746dcd12bb2353bc66bb7a 100644
--- a/gstlal-inspiral/lib/gstlal_snglinspiral.c
+++ b/gstlal-inspiral/lib/gstlal_snglinspiral.c
@@ -184,6 +184,7 @@ static int sngl_inspiral_row_callback(struct ligolw_table *table, struct ligolw_
 int gstlal_snglinspiral_array_from_file(const char *filename, SnglInspiralTable **bankarray)
 {
 	SnglInspiralTable *head = NULL;
+	SnglInspiralTable *row;
 	ezxml_t xmldoc;
 	ezxml_t elem;
 	struct ligolw_table *table;
@@ -229,6 +230,13 @@ int gstlal_snglinspiral_array_from_file(const char *filename, SnglInspiralTable
 
 	ezxml_free(xmldoc);
 
+	/*
+	 * count rows.  can't use table->n_rows because the callback
+	 * interecepted the rows, and the table object is empty
+	 */
+
+	for(num = 0, row = head; row; row = row->next, num++);
+
 	/*
 	 * copy the linked list of templates into the template array in
 	 * reverse order.  the linked list is reversed with respect to the
@@ -236,14 +244,8 @@ int gstlal_snglinspiral_array_from_file(const char *filename, SnglInspiralTable
 	 * in the order in which they appear in the file.
 	 */
 
-	{
-	/* can't use table->n_rows because the callback interecepted the
-	 * rows, and the table object is empty */
-	SnglInspiralTable *row = head;
-	for(num = 0; row; row = row->next, num++);
-	}
 	*bankarray = calloc(num, sizeof(**bankarray));
-	while(num--) {
+	for(row = &(*bankarray)[num - 1]; head; row--) {
 		SnglInspiralTable *next = head->next;
 
 		/* fix broken columns */
@@ -253,7 +255,7 @@ int gstlal_snglinspiral_array_from_file(const char *filename, SnglInspiralTable
 		head->mchirp = gstlal_mchirp(head->mass1, head->mass2);
 		head->eta = gstlal_eta(head->mass1, head->mass2);
 
-		(*bankarray)[num] = *head;
+		*row = *head;
 		LALFree(head);
 		head = next;
 	}