bug fix and unit test.