Thanks @daurnimator for catching this.
This is the part of #3960 that has to be rewritten to apply to latest master branch code.