Added the total_distance function