Added main loop procedure.