add is_of_type function and use it instead of pattern matching