fixed problems described in issue #1 and issue #2
Merge pull request #3 from fredzhou/master

fixed problems described in issue #1 and issue #2