Pretty much final version, with two elusive bugs.