adds (a probably buggy) patching algorithm