Fix issues with previous and next buttons on pagination