Added docs and refactoring