done calculate total distance function