fixed issue 340 & 400

bug
Merge pull request #438 from safiyu/issue

fixed issue 340 & 400