more tests + refactoring