refactor scoping