Refactor how variable scopes work

refs #8074