made other iterators nested, completed spaning tree algorithm