Minor refactoring, documentation and cleanup