refactor code to use a factory method on the base class and create the correct subtypes