bug fix and optimize kmeans and knn