Sorting by priority