refactor to calculateDistance