restructure AST