First (mostly) working version.