Refactored pagination controller