Adding sort_match. New hist_distance functions