kd tree work