refactoring the scope handling to enforce scope visibility and allow for more flexible extensibility with custom scopes