Update to use factory pattern