Clean up, move some global variable initialization for safety.