complex refactoring of the scoping mechanism