Refactoring, more tests