Refactoring the classes that use the class casts