Code fixes

Various code fixes, mostly discovered by MSVC code static analyzer .
I'd almost vote on skipping this, and in the logging case below you do GetText().c_str() as its a bit more safe (if someone decides to use the pointer for something and its changed)