Revised patch (per ferrieux)