fixing corner cases for pagination