Modified pagination logic