added calculate TotalDistance function