Merge pull request #379 from cpoulain/master

Merge fixes for #317, #339, #365 from willum070