coverity found some bugs
this was all wrong
fix some style errors detected by cppcheck