improved distance and time calculation algorithms