refactored some methods using type checking