improve implementation of k-medoids