Improved bfs and dfs so that their similarity is now even more obvious.