A probably working, but untested version