Sorting function added