Discovered that multi-index iterators are not as robust as I would have hoped. This code puts some safeguards in place.