Made the game pause when the window is not in focus and cleaned up code.