Clustering function.