Add support for `lookup` and clean up how ref/handle mappings are handled.