Cleanup and documentation.

Should be ready to start incorporating into some other projects.