 		// 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);

		cudaFree(gpu_ret_indexes);

	}
}
		cudaFree(m_gpu_points);
	}

	void CUDA_KDTree::CreateKDtree(KDNode *root, int num_nodes, const std::vector<Kd_tree_point> &data, int max_level)
	{
		m_num_points = data.size();

		cudaMalloc((void**)&m_gpu_nodes, sizeof(CUDA_KDNode) * num_nodes);
		cudaMalloc((void**)&m_gpu_indexes, sizeof(int) * m_num_points * (max_level + 1));
		cudaMalloc((void**)&m_gpu_points, sizeof(Kd_tree_point) * m_num_points);

		CheckCUDAError("CreateKDtree");

		std::vector <CUDA_KDNode> cpu_nodes(num_nodes);
		std::vector <int> indexes(m_num_points * (max_level + 1));
		std::vector <KDNode*> to_visit;

		int cur_pos = 0;
