Minor bug fix.
Added unit tests.