Consolidate handling of scopes.

Reviewed in https://codereview.appspot.com/6853060/.
7 files changed