sort function completed