Updated pagination logic