Fixed a bug.
Added unit tests