Refactored everything. Moved game loop to key handler function.