fixed some global var leaks