Moved all the magic to a Factory class