re-organized code
kmeans algorithm for clustering