diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..78fb1fcefe78e8a695ea479d1f738fac922cdea0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.gdb_history
diff --git a/Makefile b/Makefile
index 68519fe9175161a6581c3f8046f83f8f1ebbb581..813093fc4dfc4d0a8d361b0e4ed3dec40b7e8619 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,7 @@ DEBUG_TEST_FLAGS=-fdump-tree-all -fdump-tree-all-graph
 # Comment to disable debug
 FLAGS+=$(DEBUG_FLAGS)
 #TEST_FLAGS+=$(DEBUG_TEST_FLAGS)
-
+#GDB_GCC=-wrapper gdb,--args
 
 
 # Directories
@@ -62,7 +62,7 @@ dots:
 	$(MAKE) $(shell find $(DOTD) -name "*.dot" | sed 's/\.dot/\.svg/')
 
 $(TESTD)/%: $(TESTSRCD)/%.c
-	$(CC) $(TEST_FLAGS) $(PLUGIN_FLAGS) $^ -o $@
+	$(CC) $(GDB_GCC) $(TEST_FLAGS) $(PLUGIN_FLAGS) $^ -o $@
 
 $(OBJD)/%.o: $(SRCD)/%.cpp 
 	$(CXX) $(FLAGS) $(PLUGIN_INCLUDE) -c $^ -o $@
diff --git a/include/pass_mpi_collective.hpp b/include/pass_mpi_collective.hpp
index b620a5d78a37fa04465ea3e8ee95a2ab49eb5cc1..73fe91feb6a4fab05089186096c9b18305fe23e2 100644
--- a/include/pass_mpi_collective.hpp
+++ b/include/pass_mpi_collective.hpp
@@ -32,6 +32,7 @@ struct bb_data
 	int mark1; // for graph parkour
 	int mark2;
 	int *collective_rank;
+	bitmap_head seens;
 };
 
 struct edge_data
@@ -83,16 +84,18 @@ public:
 	// loop detection
 	void __mark_edge_naif(function *fun);
 	void __mark_edge_naif(basic_block bb);
+	void __mark_edge(function *fun);
 	void mark_edge(function *fun);
+	void mark_edge(basic_block bb);
 
 	// rank definition
 	void rank_collective(function *fun);
 	void __rank_collective(basic_block bb);
-	
+
 	//post-dom set of same-rank collectives
-	bool __is_pd_set_mpi_coll_rank(function* fun, basic_block bb, int rank
-																 , int mpi_code, bitmap pd);
-	bitmap_head __get_set_mpi_coll_rank(function* fun, int rank, int mpi_code);
+	bool __is_pd_set_mpi_coll_rank(function *fun, basic_block bb, int rank
+	                               , int mpi_code, bitmap pd);
+	bitmap_head __get_set_mpi_coll_rank(function *fun, int rank, int mpi_code);
 
 	void better_rank_collective(function *fun);
 	int __better_rank_collective(basic_block bb,
diff --git a/src/pass_mpi_collective.cpp b/src/pass_mpi_collective.cpp
index e18c4ad8ee41203c6ea0bd932e51a17149030f5a..660caf4bc7c7beef94739fa7f0646843dff30ded 100644
--- a/src/pass_mpi_collective.cpp
+++ b/src/pass_mpi_collective.cpp
@@ -70,7 +70,7 @@ unsigned int pass_mpi_collective::execute(function *fun)
 	mark_edge(fun);
 	rank_collective(fun);
 	//better_rank_collective(fun);
-	
+
 	bitmap_head pdbitmap = __get_set_mpi_coll_rank(fun, 2, MPI_BARRIER);
 	debug_bitmap(&pdbitmap);
 
@@ -202,13 +202,14 @@ void pass_mpi_collective::alloc_bb_aux(function *fun)
 	FOR_ALL_BB_FN(bb, fun)
 	{
 		bb->aux = (bb_data *) new bb_data();
-		((bb_data *) bb->aux)->collective_rank =
+		bb_data *data = ((bb_data *) bb->aux);
+		data->collective_rank =
 		  new int[(int) LAST_AND_UNUSED_MPI_COLLECTIVE_CODE];
 		for (int i = 0; i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; ++i)
 		{
-			((bb_data *) bb->aux)->collective_rank[i] = 0;
+			data->collective_rank[i] = 0;
 		}
-
+		bitmap_initialize(&data->seens, NULL);
 	}
 }
 
@@ -242,7 +243,9 @@ void pass_mpi_collective::free_bb_aux(function *fun)
 	{
 		if (bb->aux != NULL)
 		{
-			delete ((bb_data *) bb->aux)->collective_rank;
+			bb_data *data = ((bb_data *) bb->aux);
+			delete data->collective_rank;
+			bitmap_clear(&data->seens);
 			delete (bb_data *) bb->aux;
 			bb->aux = NULL;
 		}
@@ -429,7 +432,7 @@ void pass_mpi_collective::__mark_edge_naif(basic_block bb)
 	((bb_data *) bb->aux)->mark1 = 0;
 }
 
-void pass_mpi_collective::mark_edge(function *fun)
+void pass_mpi_collective::__mark_edge(function *fun)
 {
 
 	edge e1;
@@ -502,46 +505,37 @@ void pass_mpi_collective::mark_edge(function *fun)
 	reset_bb_mark(fun);
 }
 
-// WIP for new mark edge
-//struct basic_block_elem {
-//	bitmap_head seen;
-//	basic_block bb;
-//}
-//
-//struct basic_block_elem *new_bb_elem(){
-//	return new
-//}
-//
-//void free_bb_elem(){
-//
-//}
-//
-//
-//void mark_loop(){
-//	vect<struct basic_block_elem> pile;
-//	struct basic_block_elem *first;
-//
-//	first = new_bb_elem();
-//	first->bb = ENTRY_BLOCK_PTR_FOR_FN(fun);
-//	pile.push(first);
-//
-//	while(pile.length() != 0){
-//		// mettre a jour edge & already seen
-//
-//	}
-//
-//}
-//
-//void pass_mpi_collective::mark_edge(function *fun)
-//{
-//	edge e;
-//	edge_iterator ei;
-//	std::list<basic_block> nodes;
-//	basic_block bb;
-//
-//
-//
-//}
+void pass_mpi_collective::mark_edge(function *fun)
+{
+	mark_edge(ENTRY_BLOCK_PTR_FOR_FN(fun));
+	reset_bb_mark(fun);
+}
+
+void pass_mpi_collective::mark_edge(basic_block bb)
+{
+	edge e;
+	edge_iterator ei;
+
+	((bb_data *) bb->aux)->mark1 = 1;
+	bitmap_set_bit(&((bb_data *) bb->aux)->seens, bb->index);
+	FOR_EACH_EDGE(e, ei, bb->succs)
+	{
+		if (((edge_data *) e->aux)->loop)
+		{
+			continue;
+		}
+		if (bitmap_bit_p(&((bb_data *) bb->aux)->seens, e->dest->index))
+		{
+			((edge_data *) e->aux)->loop = true;
+		}
+		if (! ((bb_data *) e->dest->aux)->mark1)
+		{
+			bitmap_ior_into(&((bb_data *) e->dest->aux)->seens,
+			                &((bb_data *) bb->aux)->seens);
+			mark_edge(e->dest);
+		}
+	}
+}
 
 void pass_mpi_collective::rank_collective(function *fun)
 {
@@ -580,7 +574,6 @@ void pass_mpi_collective::__rank_collective(basic_block bb)
 			}
 		}
 	}
-	return;
 }
 
 void pass_mpi_collective::better_rank_collective(function *fun)
@@ -633,35 +626,35 @@ int pass_mpi_collective::__better_rank_collective(basic_block bb,
 	{
 		next_rank++;
 	}
-	
+
 	((bb_data *) bb->aux)->collective_rank[mpi_code] = next_rank;
 	return next_rank;
 }
 
-bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function* fun
-																										, basic_block bb
-																										, int rank
-																										, int mpi_code
-																										, bitmap pds)
+bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function *fun
+  , basic_block bb
+  , int rank
+  , int mpi_code
+  , bitmap pds)
 {
 	edge e;
 	edge_iterator ei;
-	
+
 	//printf("entered bb->index : %i\n",bb->index);
 	((bb_data *) bb->aux)->mark1 = 1;
-	
-	if (((bb_data *) bb->aux)->collective_rank[mpi_code]  
-			== rank) //if we are in the pd set
-	{ 	
+
+	if (((bb_data *) bb->aux)->collective_rank[mpi_code]
+	    == rank) //if we are in the pd set
+	{
 		bitmap_set_bit(pds, bb->index);
 		return true;
 	}
-	
+
 	if (bb == EXIT_BLOCK_PTR_FOR_FN(fun))
 	{
 		return false;
-	} 	
-	
+	}
+
 	bool is_pd_by_set = true;//is postdominated by set
 	int count_edges  = 0;
 
@@ -672,7 +665,7 @@ bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function* fun
 			//printf("loop detected... Jumping out...\n");
 			continue; //if marked as a loop or already visited, ignore
 		}
-		
+
 		count_edges++;
 		//printf("%i: %i\n",bb->index, count_edges);
 		if (((bb_data *) e->dest->aux)->mark1)
@@ -680,17 +673,17 @@ bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function* fun
 			//printf("node %i already visited.. jumping out...\n", e->dest->index);
 			is_pd_by_set = is_pd_by_set && bitmap_bit_p(pds, e->dest->index);
 			continue; //if already visited, ignore
-		} 
+		}
 
-		is_pd_by_set = 
-			 __is_pd_set_mpi_coll_rank(fun, e->dest, rank, mpi_code, pds) 
-			 && is_pd_by_set;
+		is_pd_by_set =
+		  __is_pd_set_mpi_coll_rank(fun, e->dest, rank, mpi_code, pds)
+		  && is_pd_by_set;
 	}
-	
+
 	if (count_edges == 0)
 	{
 		return false; //we are in a leaf
-	} 
+	}
 
 	if (is_pd_by_set) // add the bb to the pdset if it is pd by set.
 	{
@@ -700,18 +693,18 @@ bool pass_mpi_collective::__is_pd_set_mpi_coll_rank(function* fun
 	return is_pd_by_set;
 }
 
-bitmap_head pass_mpi_collective::__get_set_mpi_coll_rank(function* fun
-																													, int rank
-																													, int mpi_code)
+bitmap_head pass_mpi_collective::__get_set_mpi_coll_rank(function *fun
+  , int rank
+  , int mpi_code)
 {
 	bitmap_head set_post_dommed;
 	bitmap_initialize(&set_post_dommed, &bitmap_default_obstack);
-	
+
 	__is_pd_set_mpi_coll_rank(fun, ENTRY_BLOCK_PTR_FOR_FN(fun)
-														, rank, mpi_code, &set_post_dommed);
+	                          , rank, mpi_code, &set_post_dommed);
 
 	return set_post_dommed;
-} 
+}
 //============================	GRAPHVIZ  =====================================
 
 /* Build a filename (as a string) based on function name */