More tests. Code refactoring