implemented top-down kmeans hierarchy