fixed crashing BFS/DFS