More tests, refactoring