Changed sort function