New AST optimization algorithm