Implemented sortByPriority comparator