It's better to use BFS instead of DFS for this task (optional fix)