add tests + refactoring