renamed dist_mat to distance_functions