completed main loop