Implements refactored pagination code