Fixing a bug with pagination