Modifications to support automatic clustering
adding debugging to the clustering