Improve efficiency of clustering algorithm