fixes bugs in nextPages and previousPages