Ken's (mostly) working code...