Cleaned up code and added a game loop.