Rearrange some code for clarity.