major refactoring of functions in the AST