refactor using polymorphism