unit tests and refactorings