--- a/ScaleSpace.c
+++ b/ScaleSpace.c
@@ -44,7 +44,7 @@
 
 DScaleSpace* OctavePyramid_GetScaleSpace(OctavePyramid* self, int idx)
 {
-	return ArrayList_GetItem(self->octaves, idx);
+	return (DScaleSpace*) ArrayList_GetItem(self->octaves, idx);
 }
 
 // Build the largest possible number of octaves, each holding
@@ -119,7 +119,7 @@
 
 ImageMap* DScaleSpace_GetGaussianMap (DScaleSpace* self, int idx)
 {
-	return ArrayList_GetItem(self->imgScaled, idx);
+	return (ImageMap*) ArrayList_GetItem(self->imgScaled, idx);
 }
 
 // The last created gaussian map, with 2 \sigma blur. (For use with next
@@ -130,7 +130,7 @@
 	if (ArrayList_Count(self->imgScaled) < 2)
 		FatalError ("bu keneng: too few gaussian maps");
 	
-	return ArrayList_GetItem(self->imgScaled, ArrayList_Count(self->imgScaled) - 2);
+	return (ImageMap*) ArrayList_GetItem(self->imgScaled, ArrayList_Count(self->imgScaled) - 2);
 }
 
 int DScaleSpace_Count(DScaleSpace* self)
@@ -141,7 +141,7 @@
 // Return a single DoG map
 ImageMap* DScaleSpace_GetMap(DScaleSpace* self, int idx) 
 {
-	return ArrayList_GetItem(self->spaces, idx);
+	return (ImageMap*) ArrayList_GetItem(self->spaces, idx);
 }
 
 // Generate keypoints from localized peak list.
@@ -155,7 +155,7 @@
 	
 	int i;
 	for (i=0; i<ArrayList_Count(localizedPeaks); i++) {
-		ScalePoint* sp = ArrayList_GetItem(localizedPeaks, i);
+		ScalePoint* sp = (ScalePoint*) ArrayList_GetItem(localizedPeaks, i);
 
 		// Generate zero or more keypoints from the scale point locations.
 		// TODO: make the values configurable
@@ -164,14 +164,14 @@
 
 		// Generate the feature descriptor.
 		selfPointKeys = DScaleSpace_CreateDescriptors (self, selfPointKeys,
-							       ArrayList_GetItem(self->magnitudes, sp->level), 
-							       ArrayList_GetItem(self->directions, sp->level), 2.0, 4, 8, 0.2);
+							       (ImageMap*) ArrayList_GetItem(self->magnitudes, sp->level), 
+							       (ImageMap*) ArrayList_GetItem(self->directions, sp->level), 2.0, 4, 8, 0.2);
 
 		// Only copy over those keypoints that have been successfully
 		// assigned a descriptor (feature vector).
 		int j;
 		for(j=0; j<ArrayList_Count(selfPointKeys); j++) {
-			Keypoint* kp = ArrayList_GetItem(selfPointKeys, j);
+			Keypoint* kp = (Keypoint*) ArrayList_GetItem(selfPointKeys, j);
 			
 			if (kp->hasFV == false)
 				FatalError ("should not happen");
@@ -239,8 +239,8 @@
 	int radius = (int) (3.0 * sigma / 2.0 + 0.5);
 	int radiusSq = radius * radius;
 
-	ImageMap* magnitude = ArrayList_GetItem(self->magnitudes, point->level);
-	ImageMap* direction = ArrayList_GetItem(self->directions, point->level);
+	ImageMap* magnitude = (ImageMap*) ArrayList_GetItem(self->magnitudes, point->level);
+	ImageMap* direction = (ImageMap*) ArrayList_GetItem(self->directions, point->level);
 
 	// As the point may lie near the border, build the rectangle
 	// coordinates we can still reach, minus the border pixels, for which
@@ -382,7 +382,7 @@
 		else if (degree > M_PI)
 			degree -= 2.0 * M_PI;
 
-		Keypoint* kp = Keypoint_new (ArrayList_GetItem(self->imgScaled, point->level),
+		Keypoint* kp = Keypoint_new ((ImageMap*)ArrayList_GetItem(self->imgScaled, point->level),
 					     point->x + point->local->fineX,
 					     point->y + point->local->fineY,
 					     imgScale, kpScale, degree);
@@ -529,7 +529,7 @@
 	
 	int i;
 	for (i=0; i<ArrayList_Count(keypoints); i++) {
-		Keypoint* kp = ArrayList_GetItem(keypoints,i);
+		Keypoint* kp = (Keypoint*) ArrayList_GetItem(keypoints,i);
 		// The angle to rotate with: negate the orientation.
 		double angle = -kp->orientation;
 		
@@ -742,14 +742,14 @@
 {
 	ArrayList* filtered = ArrayList_new0 (NULL);
 	
-	ImageMap* space0 = ArrayList_GetItem(self->spaces, 0);
+	ImageMap* space0 = (ImageMap*) ArrayList_GetItem(self->spaces, 0);
 	int** processed = IntMap_new(space0->xDim, space0->yDim);
 	
 	int i;
 	for(i=0; i<ArrayList_Count(peaks); i++) {
 		ScalePoint* peak = (ScalePoint*)ArrayList_GetItem(peaks, i);
 		
-		if (DScaleSpace_IsTooEdgelike (self, ArrayList_GetItem(self->spaces, peak->level), peak->x, peak->y, edgeRatio))
+		if (DScaleSpace_IsTooEdgelike (self, (ImageMap*) ArrayList_GetItem(self->spaces, peak->level), peak->x, peak->y, edgeRatio))
 			continue;
 		
 		// When the localization hits some problem, i.e. while moving the
@@ -805,7 +805,7 @@
 		if (point->level <= 0 || point->level >= (ArrayList_Count(self->spaces) - 1))
 			return (true);
 		
-		ImageMap* space = ArrayList_GetItem(self->spaces,point->level);
+		ImageMap* space = (ImageMap*) ArrayList_GetItem(self->spaces,point->level);
 		if (x <= 0 || x >= (space->xDim - 1))
 			return (true);
 		if (y <= 0 || y >= (space->yDim - 1))
@@ -919,9 +919,9 @@
 	if (point->level <= 0 || point->level >= (ArrayList_Count(self->spaces) - 1))
 		FatalError ("point.Level is not within [bottom-1;top-1] range");
 	
-	ImageMap* below = ArrayList_GetItem(self->spaces, level - 1);
-	ImageMap* current = ArrayList_GetItem(self->spaces, level);
-	ImageMap* above = ArrayList_GetItem(self->spaces, level + 1);
+	ImageMap* below = (ImageMap*) ArrayList_GetItem(self->spaces, level - 1);
+	ImageMap* current = (ImageMap*) ArrayList_GetItem(self->spaces, level);
+	ImageMap* above = (ImageMap*) ArrayList_GetItem(self->spaces, level + 1);
 	
 	SimpleMatrix* H = SimpleMatrix_new (3, 3);
 	H->values[0][0] = below->values[x][y] - 2 * current->values[x][y] + above->values[x][y];
@@ -1091,7 +1091,7 @@
 	// gradient information there.
 	int s;
 	for ( s = 1 ; s < (Count - 1) ; ++s) {
-		ImageMap* imgScaledAtS = ArrayList_GetItem(self->imgScaled,s);
+		ImageMap* imgScaledAtS = (ImageMap*) ArrayList_GetItem(self->imgScaled,s);
 
 		ImageMap* magnitudeAtS = ImageMap_new (imgScaledAtS->xDim, imgScaledAtS->yDim);
 		ImageMap* directionsAtS = ImageMap_new (imgScaledAtS->xDim, imgScaledAtS->yDim);
@@ -1152,9 +1152,9 @@
 		// XXX: order correct? It should not really matter as we search
 		// for both minimums and maximums, but still, what is recommended?
 		// (otherwise maybe the gradient directions are inverted?)
-		ImageMap* imgScaledAtSnPlus1 = ArrayList_GetItem(self->imgScaled, sn+1);
-		ImageMap* imgScaledAtSn = ArrayList_GetItem(self->imgScaled, sn);
-		ImageMap* imgDiff = ImageMap_Sub(imgScaledAtSnPlus1, imgScaledAtSn);
+		ImageMap* imgScaledAtSnPlus1 = (ImageMap*) ArrayList_GetItem(self->imgScaled, sn+1);
+		ImageMap* imgScaledAtSn = (ImageMap*) ArrayList_GetItem(self->imgScaled, sn);
+		ImageMap* imgDiff = (ImageMap*) ImageMap_Sub(imgScaledAtSnPlus1, imgScaledAtSn);
 		ArrayList_SetItem(self->spaces, sn, imgDiff);
 	}
 }