Fixed a possible bug where function variables could have effects outside of their scope.