Build quadtree version top-down. Remove duplicated code between kd-tree and quadtree implementations.