This PR fixes global var leaks