Added docs with slight refactoring