fix global variable leaks