Unit test and fixes.