Add tests and fixes.