finish replace type code with polymorphism