main loop extract