--- a/TestKDTree.c
+++ b/TestKDTree.c
@@ -2,29 +2,29 @@
 
 // 2d example point class
 
-typedef struct Point Point;
-struct Point {
+struct sPoint3{
     IKDTreeDomain base;
     double* coords;
     double x;
     double y;
     double z;
 };
+typedef struct sPoint3 Point3;
 
-int Point_GetDimensionCount(Point* self) {
+int Point3_GetDimensionCount(Point3* self) {
     return (3);
 }
 
-int Point_GetDimensionElement (Point* self, int dim)
+int Point3_GetDimensionElement (Point3* self, int dim)
 {
     return self->coords[dim];
 }
 
-Point* Point_new0()
+Point3* Point3_new0()
 {
-    Point* self = (Point*)malloc(sizeof(Point));
-    self->base.getDimensionCount = Point_GetDimensionCount;
-    self->base.getDimensionElement = Point_GetDimensionElement;
+    Point3* self = (Point3*)malloc(sizeof(Point3));
+    self->base.getDimensionCount = (int ( *)(IKDTreeDomain *)) Point3_GetDimensionCount;
+    self->base.getDimensionElement = (int ( *)(IKDTreeDomain *,int))Point3_GetDimensionElement;
     self->x = 0;
     self->y = 0;
     self->z = 0;
@@ -33,9 +33,9 @@
 }
 
 
-Point*  Point_new (double x, double y, double z)
+Point3*  Point3_new (double x, double y, double z)
 {
-    Point* self = Point_new0();
+    Point3* self = Point3_new0();
     self->x = x;
     self->y = y;
     self->z = z;
@@ -45,50 +45,52 @@
     return self;
 }
 
-void Point_delete(Point* self)
+void Point3_delete(Point3* self)
 {
     free(self->coords);
     free(self);
 }
 
 
-Random* Point_rnd = NULL;
+Random* Point3_rnd = NULL;
 
-Point* Point_CreateRandomPoint (double minX, double maxX,
+Point3* Point3_CreateRandomPoint3 (double minX, double maxX,
 				double minY, double maxY,
 				double minZ, double maxZ)
 {
-    double x = Random_NextDouble (Point_rnd) * (maxX - minX) + minX;
-    double y = Random_NextDouble (Point_rnd) * (maxY - minY) + minY;
-    double z = Random_NextDouble (Point_rnd) * (maxZ - minZ) + minZ;
+    double x = Random_NextDouble (Point3_rnd) * (maxX - minX) + minX;
+    double y = Random_NextDouble (Point3_rnd) * (maxY - minY) + minY;
+    double z = Random_NextDouble (Point3_rnd) * (maxZ - minZ) + minZ;
     
-    return (Point_new (x, y, z));
+    return (Point3_new (x, y, z));
 }
 
 
 int main (int argc, char* argv[])
 {
-    ArrayList* points = ArrayList_new0 (Point_delete);
+    Point3 * target, *pt, *NN;
+    KDTree* kd;
+    double dist;
+    int n;
+    ArrayList* Point3s = ArrayList_new0 (Point3_delete);
 
-    Point_rnd = Random_new0 ();
+    Point3_rnd = Random_new0 ();
     
     // try searching for a random target
-    Point* target = Point_CreateRandomPoint (-100.0, 100.0, -100.0, 100.0, -100.0, 100.0);    
+    target = Point3_CreateRandomPoint3 (-100.0, 100.0, -100.0, 100.0, -100.0, 100.0);    
     WriteLine ("target is \nS %f %f %f", target->x, target->y, target->z);
 
-    int n;
     for ( n = 0 ; n < 20 ; ++n) {
-	Point* pt = Point_CreateRandomPoint (-100.0, 100.0, -100.0, 100.0, -100.0, 100.0);
-	WriteLine ("P %f %f %f  (distance: %f)", pt->x, pt->y, pt->z, sqrt(KDTree_DistanceSq(pt, target)));
-	ArrayList_AddItem (points, pt);
+	pt = Point3_CreateRandomPoint3 (-100.0, 100.0, -100.0, 100.0, -100.0, 100.0);
+	WriteLine ("P %f %f %f  (distance: %f)", pt->x, pt->y, pt->z, sqrt((double)KDTree_DistanceSq((IKDTreeDomain *)pt, (IKDTreeDomain *)target)));
+	ArrayList_AddItem (Point3s, pt);
     }
     
     WriteLine ("\nbuilding kd-tree");
-        KDTree* kd = KDTree_CreateKDTree (points);
+    kd = KDTree_CreateKDTree (Point3s);
     
-    double dist;
     WriteLine ("search for nearest neighbour");
-    Point* NN = (Point*)KDTree_NearestNeighbour (kd, (IKDTreeDomain*)target, &dist);
+    Point3* NN = (Point3*)KDTree_NearestNeighbour (kd, (IKDTreeDomain*)target, &dist);
     if (NN == NULL) {
 	WriteLine ("no nn found");
     } else {
@@ -103,8 +105,8 @@
 	WriteLine ("nearest distance is %f", dist);
 	int i;
 	for(i=0; i<SortedLimitedList_Count(nnlist); i++) {
-	    KDTreeBestEntry* be = SortedLimitedList_GetItem(nnlist, i);
-	    Point* nn = (Point*)be->neighbour;
+	    KDTreeBestEntry* be = (KDTreeBestEntry*) SortedLimitedList_GetItem(nnlist, i);
+	    Point3* nn = (Point3*)be->neighbour;
 	    WriteLine ("N1 %f %f %f # distance %f",
 		       nn->x, nn->y, nn->z, be->distance);
 	}
@@ -117,8 +119,8 @@
 	SortedLimitedList* nnlist = KDTree_NearestNeighbourListBBF(kd, (IKDTreeDomain*)target, 3, 20);
 	int i;
 	for(i=0; i<SortedLimitedList_Count(nnlist); i++) {
-	    KDTreeBestEntry* be = SortedLimitedList_GetItem(nnlist, i);
-	    Point* nn = (Point*)be->neighbour;
+	    KDTreeBestEntry* be = (KDTreeBestEntry*) SortedLimitedList_GetItem(nnlist, i);
+	    Point3* nn = (Point3*)be->neighbour;
 	    WriteLine ("N2 %f %f %f # distance %f",
 		       nn->x, nn->y, nn->z, be->distance);
 	}
@@ -126,10 +128,10 @@
     }
 
 
-    Point_delete(target);
+    Point3_delete(target);
     KDTree_delete(kd);
-    ArrayList_delete(points);
-    Random_delete(Point_rnd);
+    ArrayList_delete(Point3s);
+    Random_delete(Point3_rnd);
 
     return 0;
 }