Rearrange code to look better