Unit tests and bug fix.