Sorting fuction added