some code, untested.