Reapply (PUP-659) Optimize qualified variables

This reverts commit 17caf5e.

Since we've determined that the issue around the pull request (#3359)
this commit was reverting was out of date acceptance tests,
undo the revert and reapply the changes in addition to updating the
acceptance tests that were failing.