Code cleanup, and documentation.

Added documentation.
Cleaned up the code.
Added a few more documented features.