better main loop