fixed some bugs with kcluster function.