Fix coverity errors

Fix several errors from the coverity code analysis - see also #636