Factor out ScopeManager