kd tree - slow version