Refactor: replace conditionals with polymorphism