refectored code to remove the early case statements and replace them with classes and a factory