created sort function