add k-means + fix some minor issues