works after refactoring
added documentation