Slight rearrangement of switch/cases order to help compiler optimize