Corrected the priority logic.