working bfs on click