added some code for kdtree