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

Too much stack overload for me.