The sorting is to put everything back in the original order (since we pull the args apart above). The sort of the tuple sorts by the first part of the tuple (the original index).