add sort_by_priority method