New tests and refactoring