Broke main loop into two pieces.