Improved pagination helper