fix bugs for pagination