Optimized amazing version of bfs