Moved the clustering outside