Refactored the factory to support better testing