--- a/MatchKeys.c
+++ b/MatchKeys.c
@@ -36,14 +36,14 @@
 	ArrayList* matches = ArrayList_new0 (Match_delete);
 	int j;
 	for (j=0; j<ArrayList_Count(keys1); j++) {
-		KeypointN* kp = ArrayList_GetItem(keys1, j);
+		KeypointN* kp = (KeypointN*) ArrayList_GetItem(keys1, j);
 		ArrayList* kpNNList = (ArrayList*)KDTree_NearestNeighbourListBBF (kd, (IKDTreeDomain*)kp, 2, 40);
 		
 		if (ArrayList_Count(kpNNList) < 2)
 			FatalError ("BUG: less than two neighbours!");
 
-		KDTreeBestEntry* be1 = ArrayList_GetItem(kpNNList, 0);
-		KDTreeBestEntry* be2 = ArrayList_GetItem(kpNNList, 1);
+		KDTreeBestEntry* be1 = (KDTreeBestEntry*) ArrayList_GetItem(kpNNList, 0);
+		KDTreeBestEntry* be2 = (KDTreeBestEntry*) ArrayList_GetItem(kpNNList, 1);
 
 		if ((be1->distance / be2->distance) > 0.6)
 			continue;
@@ -70,7 +70,7 @@
 	// Count the references to each keypoint
 	int i;
 	for(i=0; i<ArrayList_Count(matches); i++) {
-		Match* m = ArrayList_GetItem(matches, i);
+		Match* m = (Match*) ArrayList_GetItem(matches, i);
 		int lI = (HashTable_GetItem(ht, m->kp1) == NULL) ? 0 : (int) HashTable_GetItem(ht, m->kp1);
 		HashTable_SetItem(ht, m->kp1, (void*)(lI + 1));
 		int rI = (HashTable_GetItem(ht, m->kp2) == NULL) ? 0 : (int) HashTable_GetItem(ht, m->kp2);
@@ -81,7 +81,7 @@
 	int removed = 0;
 	int j;
 	for(j=0; j<ArrayList_Count(matches); j++) {
-		Match* m = ArrayList_GetItem(matches, j);
+		Match* m = (Match*) ArrayList_GetItem(matches, j);
 		//WriteLine ("match: %d, %d", (int) HashTable_GetItem(ht, m->kp1), (int) HashTable_GetItem(ht, m->kp2));
 		
 		if (((int) HashTable_GetItem(ht, m->kp1)) <= 1 && ((int) HashTable_GetItem(ht, m->kp2)) <= 1)
@@ -145,7 +145,7 @@
 MatchWeighter* MatchWeighter_new0()
 {
 	MatchWeighter* self = (MatchWeighter*)malloc(sizeof(MatchWeighter));
-	self->comparator.compareTo = MatchWeighter_CompareTo;
+	self->comparator.compareTo = (int ( *)(IComparator *,const void *,const void *)) MatchWeighter_CompareTo;
 	self->distExp = 1.0;
 	self->quotExp = 1.0;
 	return self;
@@ -235,7 +235,7 @@
 	self->keySets = ArrayList_new(self->imageCount, KeypointXMLList_delete);
 	int n;
 	for ( n = 0 ; n < self->imageCount ; ++n) {
-	        char* fn = ArrayList_GetItem(filenames, n);
+	        char* fn = (char *) ArrayList_GetItem(filenames, n);
 		KeypointXMLList* keys = KeypointXMLReader_ReadComplete (fn);
 		if (!keys)
 			FatalError("Failed to load keypoints from %s", fn);
@@ -319,7 +319,7 @@
 	self->filteredMatchSets = ArrayList_new0 (NULL);
 	
 	// The only combination between two matches
-	MatchSet* ms = self->matchSets[0][1];
+	MatchSet* ms = (MatchSet*) self->matchSets[0][1];
 	if (ms == NULL || ms->matches == NULL)
 		return (NULL);
 
@@ -380,7 +380,7 @@
 	for ( n0 = 0 ; n0 < self->imageCount ; ++n0) {
 		int n1;
 		for ( n1 = n0 + 1 ; n1 < self->imageCount ; ++n1) {
-			MatchSet* ms = self->matchSets[n0][n1];
+			MatchSet* ms = (MatchSet*) self->matchSets[n0][n1];
 			if (ms == NULL || ms->matches == NULL)
 				continue;
 			
@@ -479,7 +479,7 @@
 	// Create a point list.
 	int i;
 	for(i=0; i<ArrayList_Count(matches); i++) {
-		Match* m = ArrayList_GetItem(matches, i);
+		Match* m = (Match*) ArrayList_GetItem(matches, i);
 		FilterPoint* p = FilterPoint_new0 ();
 
 		p->x = m->kp1->x;
@@ -590,11 +590,11 @@
 		
 		int i;
 		for(i=0; i<ArrayList_Count(matches); i++) {
-			Match* m = ArrayList_GetItem(matches, i);
+			Match* m = (Match*) ArrayList_GetItem(matches, i);
 			bool matchFound = false;
 			int j;
 			for(j=0; j<ArrayList_Count(convexHull); j++) {
-				FilterPoint* p = ArrayList_GetItem(convexHull, j);
+				FilterPoint* p = (FilterPoint*) ArrayList_GetItem(convexHull, j);
 				if (p->user != m)
 					continue;
 				
@@ -613,7 +613,7 @@
 
 			int k;
 			for(k=0; k<ArrayList_Count(convexHull); k++) {
-				FilterPoint* p = ArrayList_GetItem(convexHull, k);
+				FilterPoint* p = (FilterPoint*) ArrayList_GetItem(convexHull, k);
 				dist += sqrt (pow (p->x - m->kp1->x, 2.0) +
 					      pow (p->y - m->kp1->y, 2.0));
 				distCount += 1;
@@ -640,7 +640,7 @@
 	ArrayList* filteredMatches = ArrayList_new0 (NULL);
 	int j;
 	for(j=0; j<ArrayList_Count(convexHull); j++) {
-		FilterPoint* p = ArrayList_GetItem(convexHull, j);
+		FilterPoint* p = (FilterPoint*) ArrayList_GetItem(convexHull, j);
 		ArrayList_AddItem(filteredMatches, p->user);
 	}
 		
@@ -669,10 +669,10 @@
 {
 	int i;
 	for(i=0; i<ArrayList_Count(self->keySets); i++) {
-		KeypointXMLList* list = ArrayList_GetItem(self->keySets, i);
+		KeypointXMLList* list = (KeypointXMLList*) ArrayList_GetItem(self->keySets, i);
 		int j;
 		for(j=0; j<ArrayList_Count(list->array); j++) {
-			KeypointN* kp = ArrayList_GetItem(list->array, j);
+			KeypointN* kp = (KeypointN*) ArrayList_GetItem(list->array, j);
 			ArrayList_AddItem(self->globalKeys, kp);
 		}
 	}
@@ -695,7 +695,7 @@
 	// matches
 	int i;
 	for(i=0; i<ArrayList_Count(self->globalMatches); i++) {
-		Match* m = ArrayList_GetItem(self->globalMatches, i);
+		Match* m = (Match*) ArrayList_GetItem(self->globalMatches, i);
 		int l0 = MultiMatch_FindOrigin (self, m->kp1);
 		int l1 = MultiMatch_FindOrigin (self, m->kp2);
 		
@@ -711,11 +711,11 @@
 			continue;
 		
 		if (self->matchSets[l1][l0] != NULL) {
-			MatchSet* rev = self->matchSets[l1][l0];
+			MatchSet* rev = (MatchSet*) self->matchSets[l1][l0];
 			if (rev != NULL) {
 				int i;
 				for(i=0; i<ArrayList_Count(rev->matches); i++) {
-					Match* mr = ArrayList_GetItem(rev->matches, i);
+					Match* mr = (Match*) ArrayList_GetItem(rev->matches, i);
 					if (mr->kp1 == m->kp2 && mr->kp2 == m->kp1) {
 						reverseAlreadyIn = true;
 						
@@ -729,8 +729,8 @@
 		
 		if (self->matchSets[l0][l1] == NULL) {
 			createCount += 1;
-			KeypointXMLList* k0 = ArrayList_GetItem(self->keySets, l0);
-			KeypointXMLList* k1 = ArrayList_GetItem(self->keySets, l1);
+			KeypointXMLList* k0 = (KeypointXMLList*) ArrayList_GetItem(self->keySets, l0);
+			KeypointXMLList* k1 = (KeypointXMLList*) ArrayList_GetItem(self->keySets, l1);
 			self->matchSets[l0][l1] = MatchSet_new (self,
 								k0->imageFile, k0->xDim, k0->yDim,
 								k1->imageFile, k1->xDim, k1->yDim,
@@ -762,7 +762,7 @@
 {
 	int ksn;
 	for ( ksn = 0 ; ksn < ArrayList_Count(self->keySets) ; ++ksn) {
-		KeypointXMLList* list = ArrayList_GetItem(self->keySets, ksn);
+		KeypointXMLList* list = (KeypointXMLList*) ArrayList_GetItem(self->keySets, ksn);
 		
 		int lIdx = ArrayList_IndexOf (list->array, kp);
 		if (lIdx >= 0)
@@ -778,7 +778,7 @@
 {
 	int count = 0;
 	double searchDepth = max (130.0,
-				  (log (ArrayList_Count(self->globalKeys)) / log (1000.0)) * 130.0);
+				  (log ((double) ArrayList_Count(self->globalKeys)) / log (1000.0)) * 130.0);
 	int searchDepthI = (int) searchDepth;
 	
 	if (self->verbose)
@@ -786,10 +786,10 @@
 
 	int i;
 	for(i=0; i<ArrayList_Count(self->globalKeys); i++) {
-		KeypointN* kp = ArrayList_GetItem(self->globalKeys, i);
+		KeypointN* kp = (KeypointN*) ArrayList_GetItem(self->globalKeys, i);
 
 		if (self->verbose) {
-			if ((count % 25) == 0)
+			if ((count % 250) == 0)
 				Write ("\r%2.2f%%, %d/%d        ",
 					   (100 * ((double) count)) / ((double) ArrayList_Count(self->globalKeys)),
 					   count, ArrayList_Count(self->globalKeys));
@@ -806,16 +806,16 @@
 		if (ArrayList_Count(kpNNList) < 3)
 			FatalError ("BUG: less than three neighbours!");
 
-		KDTreeBestEntry* be1 = ArrayList_GetItem(kpNNList, 0);
-		KDTreeBestEntry* be2 = ArrayList_GetItem(kpNNList, 1);
+		KDTreeBestEntry* be1 = (KDTreeBestEntry*) ArrayList_GetItem(kpNNList, 0);
+		KDTreeBestEntry* be2 = (KDTreeBestEntry*) ArrayList_GetItem(kpNNList, 1);
 
 		// If be1 is the same (exact hit), shift one
 		if (be1->neighbour == (IKDTreeDomain*)kp) {
 			be1 = be2;
-			be2 = ArrayList_GetItem(kpNNList, 2);
+			be2 = (KDTreeBestEntry*) ArrayList_GetItem(kpNNList, 2);
 		}
 		if (be1->neighbour == (IKDTreeDomain*)kp || be2->neighbour == (IKDTreeDomain*)kp ||
-		    be1->neighbour == be2->neighbour) {
+		    be1->neighbour == (IKDTreeDomain*) be2->neighbour) {
 			ArrayList_delete(kpNNList);
 			continue;
 		}
@@ -849,7 +849,7 @@
 
 	int i;
 	for(i=0; i<ArrayList_Count(matches); i++) {
-		MatchSet* ms = ArrayList_GetItem(matches, i);
+		MatchSet* ms = (MatchSet*) ArrayList_GetItem(matches, i);
 
 		Component* c1 = MultiMatch_FindComponent (components, ms->file1);
 		Component* c2 = MultiMatch_FindComponent (components, ms->file2);
@@ -881,7 +881,7 @@
 	// the final result.
 	int j;
 	for(j=0; j<ArrayList_Count(self->keySets); j++) {
-		KeypointXMLList* klist = ArrayList_GetItem(self->keySets, j);
+		KeypointXMLList* klist = (KeypointXMLList*) ArrayList_GetItem(self->keySets, j);
 		char* filename = klist->imageFile;
 
 		if (MultiMatch_FindComponent (components, filename) != NULL)
@@ -900,7 +900,7 @@
 {
 	int i;
 	for(i=0; i<ArrayList_Count(components); i++) {
-		Component* comp = ArrayList_GetItem(components, i);
+		Component* comp = (Component*) ArrayList_GetItem(components, i);
 		if (Component_IsIncluded(comp, filename)) 
 			return (comp);
 	}
@@ -928,7 +928,7 @@
 {
 	int i;
 	for(i=0; i<ArrayList_Count(comp->files); i++) {
-		char* filename = ArrayList_GetItem(comp->files, i);
+		char* filename = (char*) ArrayList_GetItem(comp->files, i);
 		ArrayList_AddItem(self->files, filename);
 	}
 }
@@ -955,7 +955,7 @@
 	int i;
 
 	for(i=0; i<ArrayList_Count(self->files); i++) {
-		char* filename = ArrayList_GetItem(self->files, i);
+		char* filename = (char*) ArrayList_GetItem(self->files, i);
 		if (first) {
 			first = false;
 		} else {
@@ -998,7 +998,7 @@
 		MatchSet* msNext = NULL;
 		int i;
 		for(i=0; i<ArrayList_Count(ransacFiltered); i++) {
-			MatchSet* ms = ArrayList_GetItem(ransacFiltered, i);
+			MatchSet* ms = (MatchSet*) ArrayList_GetItem(ransacFiltered, i);
 			if (strcmp (ms->file1, fileNow) == 0 &&
 			    strcmp (ms->file2, fileNext) == 0)
 			{
@@ -1049,7 +1049,7 @@
 	char* last = NULL;
 	int i;
 	for(i=0; i<ArrayList_Count(bb->sets); i++) {
-		MatchSet* ms = ArrayList_GetItem(bb->sets, i);
+        MatchSet* ms = (MatchSet*) ArrayList_GetItem(bb->sets, i);
 		ArrayList_AddItem(rowFileNames, ms->file1);
 		last = ms->file2;
 	}
@@ -1058,7 +1058,7 @@
 	WriteLine ("First row is:");
 	int j;
 	for(j=0; j<ArrayList_Count(rowFileNames); j++) {
-		char* rowFileName = ArrayList_GetItem(rowFileNames, j);
+		char* rowFileName = (char*) ArrayList_GetItem(rowFileNames, j);
 		WriteLine ("  %s", rowFileName);
 	}
 
@@ -1072,7 +1072,7 @@
 	if (ArrayList_Count(bb->sets) > 2) {
 		int k;
 		for(k=0; k<ArrayList_Count(ransacFiltered); k++) {
-			MatchSet* ms = ArrayList_GetItem(ransacFiltered, k);
+			MatchSet* ms = (MatchSet*) ArrayList_GetItem(ransacFiltered, k);
 			if ((strcmp (ms->file1, bb->last->file2) == 0 &&
 			     strcmp (ms->file2, bb->first->file1) == 0) ||
 			    (strcmp (ms->file2, bb->last->file2) == 0 &&
@@ -1112,7 +1112,7 @@
 		
 		int n;
 		for(n=0; n<ArrayList_Count(ransacFiltered); n++) {
-			MatchSet* ms = ArrayList_GetItem(ransacFiltered, n);
+			MatchSet* ms = (MatchSet*) ArrayList_GetItem(ransacFiltered, n);
 			// Already aligned.
 			if (HashTable_Contains(bb->positions,ms->file1) && HashTable_Contains(bb->positions, ms->file2))
 				continue;