Make this a subclass of the factory, and perhaps move the factory into a different class? Quite a big chunk of code here?