Fixed problem with pagination edge cases