Fix bug where out of scope variable was being referenced.