plug global variable leaks. other minor linting.

removed some unused variables as well.