Rearrange variables to fix ordering issues