implementation of a KDTree