 		// Find the first closest node, this will be the upper bound for the next searches
 		int best_node = 0;
 		int* k_idx = (int*)malloc(sizeof(int) * k);
-		double* k_dist = (double*)malloc(sizeof(float) * k);
+		double* k_dist = (double*)malloc(sizeof(double) * k);
 		double radius = 0;
 
 		SearchAtNode_knn(nodes, indexes, pts, 0 /* root */, query, k_idx, k_dist, &best_node, k);

		while (nodes[cur].parent != -1)
		{
			int parent = nodes[cur].parent;
			int split_axis = nodes[cur].level % KDTREE_DIM;

			//Search the other node

			if (fabs(nodes[parent].split_value - query.coords[split_axis]) <= radius)
			{

				if (nodes[parent].left != cur)
					SearchAtiNodeRange_knn(nodes, indexes, pts, query, nodes[parent].left, radius, k_idx, k_dist, k);
				else
					SearchAtiNodeRange_knn(nodes, indexes, pts, query, nodes[parent].right, radius, k_idx, k_dist, k);

			}
			cur = parent;
		}


				//Now we get enough neighbors in cur node
				int *temp_index = (int*)malloc(sizeof(int) * nodes[cur].num_indexes);
				double *temp_dists = (double*)malloc(sizeof(double) * nodes[cur].num_indexes);

				for (int i = 0; i < nodes[cur].num_indexes; ++i)
				{
