Further improve scoping and fix exception reported by egofree.