Fix coverity fix bugs

Should fix issue #468, among others.