switch to breadth-first search

makes dependency management easier