Refactored into separate factory class