rearrange code

less magical now