Refactoring + add documentation