Rearrange code for readability