Paginate middleware