code refactored(using polymorphism)