made a few adjustments to function scopes and gameloop