Fixed bug related to misuse and abuse of globals.