Replace conditional with polymorphism