Thanks to Martijn Braam for additional patches that were squashed into this one. [ci:skip-build]: won't finish in time