Add tests and fix failures