Refactor page nesting functions