Refactored valid-type handling in lookup.