Code fixes

Various code fixes, mostly discovered by MSVC code static analyzer .
extra parentheses around the && block please.