Eliminate extra getReferenced query for all query commands. Fixes #108