update pairwise_distance routine