Coverity fixes

Fixes for issues revealed though the use of the [Coverity Scan Tool](http://scan2.coverity.com/)