Use a factory to create page switcher function