Add tests, fix bug found by tests