Clean up codebase and add some documentation.