fixed issue #370 & #518
Merge pull request #520 from safiyu/newissue

fixed issue #370 & #518