extract updatePage logic into its own function for reuse