- Modified code for better pagination handling