Add tests, fix issues