Refactoring for instanceof and proper OOP