added licence, and a bunch more tests, and a couple of fixes which the tests found.