Fix  and add a unit test for it.