Clean up codebase, improve documentation