Rearranged the order of state variables updates.