Fixes #23.
Merge pull request #33 from harikt/issue-23

Spend quite sometime to fix this serious bug