Refactored code for printing priority