tests and refactoring