refactors nextPage/previousPage