reduced stack overhead by transforming nodes as early as possible in functions