Modified the main loop.