add k-means and bug fixes