resolve #327 . Unit test is included.
Merge pull request #331 from michaelp/master

Bug fix. Resolve #327