refactored type lookup, tested