Revert bad merge and reintroduce the changes
Fixing merge conflicts in !2629 (comment 429346522), I accidentally used an older revision of the MR, resulting in a failing master. This commit reverts the bad merge and applies the changes from the latest revision of the original MR back with the merge conflicts fixed.
Edited by Sami Hiltunen