Added docs and small refactoring