Defer this code until you are out of the "if" block. Then you will only need to declare proj inside the last "if (projectionNode)" block and you can always use root as the child of proj.