refactor for variable scope access with resolving refs