Removing duplicated code in set_priority