Rewrote BF method to be iterative. Use 'if not visited[v]' instead of 'unless visited[v]' for expressiveness