Rewrite pager to make it more memory-efficient