update sort function