KdTree implementation