fix catching of relation resolutions (optimization), and related code cleanup.  now include a test to verify caching