rearrange some lines of code