Create a Factory and integrate it in the existing code.