merged patches by Guido Reina