peter's version. untested