Updated to handle pagination