Re-arrange some code for legibility