Replaced conditional switch with polymorphism