Saving the changed distances.