add tests, refactoring