Refactoring + added documentation