Fixes #311 (tests pass for that test).  But that has generated a bunch
of other failing tests which I'll work on fixing now...