main loop.