write a main loop.