Fix issue #2220
Fix issue #2335 on master
Merge pull request #276 from jtraulle/master

Fix issues #2220 and #2335