Start of global variable stuff. Also minor changes elsewhere.