bug fix in kmeans and kmedois

#1: fix some bug in kmenas and kmedois
#2: vectorize some code