Fix #368
Fix #341
Merge pull request #382 from jtorrente/issue-368

Fixes issues #368 and #341