the main loop