Could do we re-write this algorithm with pages.forEach bla bla? Thanks