rearrange a bit of code