Moved the distance function to its own module