added documentation, refactoring