Improved BFS/DFS graph API, updated code style.