Fix bug in pagination