Added comments. Misc clean up.

Added comments for readability. Cleaned up some pieces of scattered code.