outline of main loop added.