implement BFS, which seems to work much better than IDDFS