added a sort function