fix main loop.