Super extensive function created to calculate routes.