extract Sorting as a method