Rearrange code & clean up whitespace