Fix and add tests, also add copyright.