modified distance function