This is a follow-up to !1565 (merged) which I created from the commits @matthijs originally prepared for that MR.