Outsourced page change function