BFS refactoring and DFS with marked edge type