Code cleanup.

Jad, I left a few large comments in the main mod file trying to describe
why I did what I did. You can of course ask me more specific questions.