Improved pagination functionality