Code review fixes. Added unit test.