Added structure of main loop.