Fixed various global variable leaks