K-medoids implementation.