First complete, but untested version.