Merge pull request #329 from parrt/master

Lots of little fixes thanks to Coverity Scan