updated to handle pagination