Improved function to cluster reads