rearrange code for clarity