fixed logic in pagination