Rearrange update loop to fix infinite loop