refactoring type checking