fix main loop