refactor to AST generation