Tried to incorporate breadth first search.