I dont know anything about kd trees but this is my implementation in ceepulaspulas