extractClusters function

Cluster extraction utility