Move some global variables back into local scope. There is still *way* too many global variables.