I've cherry picked these two commits from David and fixed a small conflict while applying the second one. The tests also discover some issues. Will open a bug for them.
Please comment on the PR state? Do you want me to squash the two commits together ?