looping over the pages correctly