made the sort function more readable