Refactoring and documentation

Refactoring and documentation