Adding some much-needed documentation.
Cleaned up code to reduce memory use.