added non-recusrive way to bfs