First version of breadth first search.