Added comments, cleaned up various aspects.

* Just a quick run through and added comments to quite a bit of code.