Thanks to Simon Jagoe and Robert Kern for many useful suggestions, code, and
code reviews.