setup the main loop