Rearrange code slightly