refactor implementation. added docs and logs