main loop. pagination