type matching refactored