Add tests and fix