Changing some globals to local variables