helper function to calculate path distance. Front end updated to receive more data from the backend