highly optimized breadth first search