change game loop to be more flexible