Coverity inspired fixes