made rewriting of graph more dynamic