fix some bugs for kmeans termination