Add tests and fix minor bugs in units.