implemented breadth first traversal to generic tree