BFS is more preferable for this task than DFS (optional fix)