Fixes for issues discovered by Coverity