Fixing some bugs.
Fixing unit test.