Unit tests and fixes.