rearrange code structure