prevent to go on out of ranges page

When you're on first page and click prevPage button several times, rendered page doesn't change but you have to click several times nextPage button to go to second page. The same happens on last page. This commit fixed it.