Totally refactored AST handling