Cleanup, refactoring, documentation