Added a function to compute the distance