improvements for distance function and kmedoids