with minor bugs in next and previous pages in pagination