Fixed a typo, and corrected some variable leaks into the global scope.