refactoring and reformatting

Performed some much needed cleanup and refactoring of the code, including
documenting some of the existing classes.
Merge pull request #138 from valdisrigdon/cleanup

refactoring and reformatting