Index: src/work/edmonds_karp.h
===================================================================
--- src/work/edmonds_karp.h	(revision 263)
+++ src/work/edmonds_karp.h	(revision 265)
@@ -480,6 +480,6 @@
 
       MutableGraph F;
-      typedef SubGraphWrapper<AugGraph, DistanceMap<AugGraph> > FilterResGraph;
-      FilterResGraph filter_res_graph(res_graph, dist);
+      //typedef SubGraphWrapper<AugGraph, DistanceMap<AugGraph> > FilterResGraph;
+      //FilterResGraph filter_res_graph(res_graph, dist);
       typename AugGraph::NodeMap<typename MutableGraph::Node> 
 	res_graph_to_F(res_graph);
@@ -496,5 +496,7 @@
       //Making F to the graph containing the edges of the residual graph 
       //which are in some shortest paths
-      for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); res_graph.valid(e); res_graph.next(e)) {
+      for(typename AugGraph::EdgeIt e=res_graph.template first<typename AugGraph::EdgeIt>(); 
+	  res_graph.valid(e); 
+	  res_graph.next(e)) {
 	if (dist.get(res_graph.head(e))==dist.get(res_graph.tail(e))+1) {
 	  typename MutableGraph::Edge f=F.addEdge(res_graph_to_F.get(res_graph.tail(e)), res_graph_to_F.get(res_graph.head(e)));
Index: src/work/iterator_bfs_demo.cc
===================================================================
--- src/work/iterator_bfs_demo.cc	(revision 238)
+++ src/work/iterator_bfs_demo.cc	(revision 265)
@@ -100,5 +100,7 @@
     
     cout << "bfs and dfs iterator demo on the directed graph" << endl;
-    for(GW::NodeIt n=gw.first<GW::NodeIt>(); gw.valid(n); gw.next(n)) { 
+    for(GW::NodeIt n=gw.first<GW::NodeIt>(); 
+	gw.valid(n); 
+	gw.next(n)) { 
       cout << node_name.get(n) << ": ";
       cout << "out edges: ";
Index: src/work/list_graph.h
===================================================================
--- src/work/list_graph.h	(revision 260)
+++ src/work/list_graph.h	(revision 265)
@@ -311,6 +311,12 @@
     
     template <typename It> It getNext(It it) const { 
-      It tmp(it); return next(tmp); }
-    template <typename It> It& next(It& it) const { return ++it; }
+      It tmp(it); next(tmp); return tmp; }
+//     NodeIt& next(NodeIt& it) const { return ++it; }
+//     EdgeIt& next(EdgeIt& it) const { return ++it; }
+//     OutEdgeIt& next(OutEdgeIt& it) const { return ++it; }
+//     InEdgeIt& next(InEdgeIt& it) const { return ++it; }
+//     SymEdgeIt& next(SymEdgeIt& it) const { return ++it; }
+//    template <typename It> It& next(It& it) const { return ++it; }
+    template <typename It> It& next(It& it) const { ++it; return it; }
    
 
Index: src/work/marci/graph_wrapper.h
===================================================================
--- src/work/marci/graph_wrapper.h	(revision 263)
+++ src/work/marci/graph_wrapper.h	(revision 265)
@@ -16,25 +16,78 @@
 
     typedef typename Graph::Node Node;
-    typedef typename Graph::NodeIt NodeIt;
-
+    class NodeIt : public Graph::NodeIt { 
+    public:
+      NodeIt() { }
+      NodeIt(const typename Graph::NodeIt& n) : Graph::NodeIt(n) { }
+      NodeIt(const Invalid& i) : Graph::NodeIt(i) { }
+      NodeIt(const TrivGraphWrapper<Graph>& _G) : 
+	Graph::NodeIt(*(_G.graph)) { }
+    };
     typedef typename Graph::Edge Edge;
-    typedef typename Graph::OutEdgeIt OutEdgeIt;
-    typedef typename Graph::InEdgeIt InEdgeIt;
+    //typedef typename Graph::OutEdgeIt OutEdgeIt;
+    class OutEdgeIt : public Graph::OutEdgeIt { 
+    public:
+      OutEdgeIt() { }
+      OutEdgeIt(const typename Graph::OutEdgeIt& e) : Graph::OutEdgeIt(e) { }
+      OutEdgeIt(const Invalid& i) : Graph::OutEdgeIt(i) { }
+      OutEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
+	Graph::OutEdgeIt(*(_G.graph), n) { }
+    };
+    //typedef typename Graph::InEdgeIt InEdgeIt;
+    class InEdgeIt : public Graph::InEdgeIt { 
+    public:
+      InEdgeIt() { }
+      InEdgeIt(const typename Graph::InEdgeIt& e) : Graph::InEdgeIt(e) { }
+      InEdgeIt(const Invalid& i) : Graph::InEdgeIt(i) { }
+      InEdgeIt(const TrivGraphWrapper<Graph>& _G, const Node& n) : 
+	Graph::InEdgeIt(*(_G.graph), n) { }
+    };
     //typedef typename Graph::SymEdgeIt SymEdgeIt;
-    typedef typename Graph::EdgeIt EdgeIt;
+    //typedef typename Graph::EdgeIt EdgeIt;
+    class EdgeIt : public Graph::EdgeIt { 
+    public:
+      EdgeIt() { }
+      EdgeIt(const typename Graph::EdgeIt& e) : Graph::EdgeIt(e) { }
+      EdgeIt(const Invalid& i) : Graph::EdgeIt(i) { }
+      EdgeIt(const TrivGraphWrapper<Graph>& _G) : 
+	Graph::EdgeIt(*(_G.graph)) { }
+    };
 
     //TrivGraphWrapper() : graph(0) { }
     TrivGraphWrapper(Graph& _graph) : graph(&_graph) { }
 
-    void setGraph(Graph& _graph) { graph = &_graph; }
-    Graph& getGraph() const { return (*graph); }
-    
-    template<typename I> I& first(I& i) const { return graph->first(i); }
-    template<typename I, typename P> I& first(I& i, const P& p) const { 
-      return graph->first(i, p); }
-    
-    template<typename I> I getNext(const I& i) const { 
-      return graph->getNext(i); }
-    template<typename I> I& next(I &i) const { return graph->next(i); }    
+//    void setGraph(Graph& _graph) { graph = &_graph; }
+//    Graph& getGraph() const { return (*graph); }
+
+    NodeIt& first(NodeIt& i) const { 
+      i=NodeIt(*this);
+      return i;
+    }
+    EdgeIt& first(EdgeIt& i) const { 
+      i=EdgeIt(*this);
+      return i;
+    }
+//     template<typename I> I& first(I& i) const { 
+//       //return graph->first(i); 
+//       i=I(*this);
+//       return i;
+//     }
+    OutEdgeIt& first(OutEdgeIt& i, const Node& p) const { 
+      i=OutEdgeIt(*this, p);
+      return i;
+    }
+    InEdgeIt& first(InEdgeIt& i, const Node& p) const { 
+      i=InEdgeIt(*this, p);
+      return i;
+    }
+//     template<typename I, typename P> I& first(I& i, const P& p) const { 
+//       //return graph->first(i, p);
+//       i=I(*this, p);
+//       return i;
+//     }
+    
+//    template<typename I> I getNext(const I& i) const { 
+//      return graph->getNext(i); }
+    template<typename I> I& next(I &i) const { graph->next(i); return i; }    
 
     template< typename It > It first() const { 
@@ -72,7 +125,7 @@
     public:
       NodeMap(const TrivGraphWrapper<Graph>& _G) : 
-	Graph::NodeMap<T>(_G.getGraph()) { }
+	Graph::NodeMap<T>(*(_G.graph)) { }
       NodeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
-	Graph::NodeMap<T>(_G.getGraph(), a) { }
+	Graph::NodeMap<T>(*(_G.graph), a) { }
     };
 
@@ -80,7 +133,7 @@
     public:
       EdgeMap(const TrivGraphWrapper<Graph>& _G) : 
-	Graph::EdgeMap<T>(_G.getGraph()) { }
+	Graph::EdgeMap<T>(*(_G.graph)) { }
       EdgeMap(const TrivGraphWrapper<Graph>& _G, T a) : 
-	Graph::EdgeMap<T>(_G.getGraph(), a) { }
+	Graph::EdgeMap<T>(*(_G.graph), a) { }
     };
   };
@@ -94,12 +147,56 @@
     //typedef typename GraphWrapper::BaseGraph BaseGraph;
 
+//     typedef typename GraphWrapper::Node Node;
+//     typedef typename GraphWrapper::NodeIt NodeIt;
+
+//     typedef typename GraphWrapper::Edge Edge;
+//     typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
+//     typedef typename GraphWrapper::InEdgeIt InEdgeIt;
+//     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
+//     typedef typename GraphWrapper::EdgeIt EdgeIt;
+
     typedef typename GraphWrapper::Node Node;
-    typedef typename GraphWrapper::NodeIt NodeIt;
-
+    class NodeIt : public GraphWrapper::NodeIt { 
+    public:
+      NodeIt() { }
+      NodeIt(const typename GraphWrapper::NodeIt& n) : 
+	GraphWrapper::NodeIt(n) { }
+      NodeIt(const Invalid& i) : GraphWrapper::NodeIt(i) { }
+      NodeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
+	GraphWrapper::NodeIt(_G.gw) { }
+    };
     typedef typename GraphWrapper::Edge Edge;
-    typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
-    typedef typename GraphWrapper::InEdgeIt InEdgeIt;
+    //typedef typename GraphWrapper::OutEdgeIt OutEdgeIt;
+    class OutEdgeIt : public GraphWrapper::OutEdgeIt { 
+    public:
+      OutEdgeIt() { }
+      OutEdgeIt(const typename GraphWrapper::OutEdgeIt& e) : 
+	GraphWrapper::OutEdgeIt(e) { }
+      OutEdgeIt(const Invalid& i) : GraphWrapper::OutEdgeIt(i) { }
+      OutEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
+	GraphWrapper::OutEdgeIt(_G.gw, n) { }
+    };
+    //typedef typename GraphWrapper::InEdgeIt InEdgeIt;
+    class InEdgeIt : public GraphWrapper::InEdgeIt { 
+    public:
+      InEdgeIt() { }
+      InEdgeIt(const typename GraphWrapper::InEdgeIt& e) : 
+	GraphWrapper::InEdgeIt(e) { }
+      InEdgeIt(const Invalid& i) : GraphWrapper::InEdgeIt(i) { }
+      InEdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G, const Node& n) : 
+	GraphWrapper::InEdgeIt(_G.gw, n) { }
+    };
     //typedef typename GraphWrapper::SymEdgeIt SymEdgeIt;
-    typedef typename GraphWrapper::EdgeIt EdgeIt;
+    //typedef typename GraphWrapper::EdgeIt EdgeIt;
+    class EdgeIt : public GraphWrapper::EdgeIt { 
+    public:
+      EdgeIt() { }
+      EdgeIt(const typename GraphWrapper::EdgeIt& e) : 
+	GraphWrapper::EdgeIt(e) { }
+      EdgeIt(const Invalid& i) : GraphWrapper::EdgeIt(i) { }
+      EdgeIt(const GraphWrapperSkeleton<GraphWrapper>& _G) : 
+	GraphWrapper::EdgeIt(_G.gw) { }
+    };
+
 
     //GraphWrapperSkeleton() : gw() { }
@@ -109,10 +206,15 @@
     //BaseGraph& getGraph() const { return gw.getGraph(); }
     
-    template<typename I> I& first(I& i) const { return gw.first(i); }
+    template<typename I> I& first(I& i) const {       
+      i=I(*this);
+      return i;
+    }
     template<typename I, typename P> I& first(I& i, const P& p) const { 
-      return gw.first(i, p); }
-    
-    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
-    template<typename I> I& next(I &i) const { return gw.next(i); }    
+      i=I(*this, p);
+      return i; 
+    }
+    
+//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
+    template<typename I> I& next(I &i) const { gw.next(i); return i; }    
 
     template< typename It > It first() const { 
@@ -656,7 +758,7 @@
     }
 
-    template<typename I> I& first(I& i) const { return gw.first(i); }
+    template<typename I> I& first(I& i) const { gw.first(i); return i; }
     template<typename I, typename P> I& first(I& i, const P& p) const { 
-      return graph->first(i, p); }
+      graph->first(i, p); return i; }
 
     OutEdgeIt& next(OutEdgeIt& e) const {
@@ -682,5 +784,5 @@
 
     template<typename I> I& next(I &i) const { return gw.next(i); }    
-    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
+//    template<typename I> I getNext(const I& i) const { return gw.getNext(i); }
 
     template< typename It > It first() const { 
@@ -814,12 +916,12 @@
   public:
     //typedef Graph BaseGraph;
-    typedef typename Graph::Node Node;
-    typedef typename Graph::NodeIt NodeIt;
+    typedef TrivGraphWrapper<const Graph> GraphWrapper;
+    typedef typename GraphWrapper::Node Node;
+    typedef typename GraphWrapper::NodeIt NodeIt;
   private:
-    typedef typename Graph::OutEdgeIt OldOutEdgeIt;
-    typedef typename Graph::InEdgeIt OldInEdgeIt;
+    typedef typename GraphWrapper::OutEdgeIt OldOutEdgeIt;
+    typedef typename GraphWrapper::InEdgeIt OldInEdgeIt;
   protected:
     //const Graph* graph;
-    typedef TrivGraphWrapper<const Graph> GraphWrapper;
     GraphWrapper gw;
     FlowMap* flow;
@@ -872,5 +974,5 @@
       OutEdgeIt(const Edge& e) : Edge(e) { }
       OutEdgeIt(const Invalid& i) : Edge(i) { }
-    private:
+    protected:
       OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() { 
 	resG.gw.first(out, v);
@@ -906,5 +1008,5 @@
     class EdgeIt : public Edge {
       friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
-      typename Graph::NodeIt v;
+      NodeIt v; 
     public:
       EdgeIt() { }
