Coverity fixes

Mostly cosmetic changes, and some cppcheck fixes