This is a fixup of c8873b52, which did not bring over all the changes in the original commit.
The original was 3ccc80ee