done except kdtree optimization