A more or less working version.