Switched from bfs to depth first search.