Naive but efficient implementation of pagination.