bug 794: complete rewrite of the patch