Thanks to Johan review, this is an updated version of the patch. Fabien