Use polymorphism to simplify the code