Refactoring the functions that change a page context var