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.

Please merge