new function for clustering