wip: start working on variable scope refactoring