Re-organized the code to make everything look pretty and neat.

This is what happens with too much stack overflow.