Random thought: A lot of this feels like it could be of more general use in other places involving pagination. Perhaps modularizing?