clustering algorithm & small changes