Refactor to use Abstract Factory pattern