Minor refactorization and start of BFS implementation.