Improved robustness of the code
Merge pull request #243 from fabienrohrer/master

Improved code