Fixes for context sensitive lookup; doesn't fix the UICatalog tests yet

Still working on the UICatalog tests. Please merge though.