Documentation and small refactoring