Made key variables have global status and moved game loops into their own functions.