refactor BFS into a path class