bfs modifiyed