Fixed issue with self-references in query lookup
128/128 tests pass.