improvement of the main loop.