Rearranged the location of the sort function.