Fix global variable leaks and references.

This commit also removes duplicate var references. While duplicate var declarations are valid in non-strict mode, I tend to like to clean those up also.
Merge pull request #209 from danshultz/global-cleanup

Fix global variable leaks and references.