Added a distance function.