Refactoring tests and factories