More tests + refactoring