Changed from depth first to breadth first