more tests and refactorings