convert mark/bernd's code to a patch
convert mark/bernd's code to a patch