I'm attaching a smaller patch that solves this in a somewhat cleaner way.