Document and rearrange code.