More tests and mofify some code...

... And spot yet more edge cases in the spec itself. Argh.