sort the function