References Issue #4

Fixed bugs in the pagination logic.