Main loop code formated