extract factory related logic to the factory from controller.