Various fixes suggested by static code analysis