bfs not longer failing in the last iteration