Fixing issue #40. Added unit tests.