main loop structure.