Replace scopes with an immutable attribute map.
Move to top level to reduce import tax.