refactor conditional to polymorphism