This is basically the same as the one on the evaluator and makes use of the ScopeStack - maybe need to generalize this more?