rearrange code a bit