Working on a distance function for matches