Factor out AST stuff