This commit a backport of a handful of merge requests to master. As
these two branches have diverged a bit and the master branch has seen a
fair bit of churn lately, it was not trivial to simply cherry-pick the
changes.
Some related merge reqtests are: !1027, !1037 and !1051.