Minor refactoring and documentation