breadth first search implemented