fix possible bug in KdTree implementation