Refactored type resolver, also takes into account named types.