Rearrange code to be more compact