The dnd fix in -5 was actually redundant, a similar fix for the
same bug had already been committed upstream. Replace it with
the upstream version, plus three other fixes from the same MR.
Also add several other fixes from post-3.30.0 git master which
look important and useful.