Making changes in the code to make the work more fast with the request of the distances