Various fixes for Coverity issues