public ASTNode expand(ASTNode term,IExpressionContext context,boolean deleteExpandedVars) 
    {
        final ASTNode result = term.createCopy( true );

        final Set<Identifier> expandedIdentifiers = new HashSet<>();

        boolean expanded = false;
        do 
        {
            expanded = false;
            final MutatingNodeVisitor visitor = new MutatingNodeVisitor( context ) {

                @Override
                public void visit(ASTNode node,IExpressionContext context,IIterationContext it) 
                {
                    final ASTNode unwrapped = unwrap( node );
                    if ( node.hasParent() && unwrapped instanceof IdentifierNode ) 
                    {
                        final ASTNode expanded = unwrapped.evaluate( context );
                        if ( expanded != null && expanded != unwrapped )
                        {
                            debugPrintln("EXPAND: Expanding "+node+" -> "+expanded);
                            expandedIdentifiers.add( ((IdentifierNode) unwrapped).getIdentifier() );
                            node.replaceWith( expanded );
                            it.astMutated();
                        } 
                    }
                }
            };

            expanded = applyPostOrder( result , visitor );
        } while ( expanded );

        if ( deleteExpandedVars ) {
            for ( Identifier id : expandedIdentifiers ) {
                context.remove( id );
            }
        }

        return result;

    }