Add tests and fix one bug