Extensive rewrite of patch drawing functions