More tests, a little doc.

BTW, I don't know how easy github makes this, but I think it would be easier to review one commit at a time instead of the whole diff.