Add pagination function.