modified conditions to prevent scrolling up on first page and scrolling down on last page.