Refactor the AST