Refactoring plus tests