Implemented breadth-first search instead of DFS