Code fixes

Various code fixes, mostly discovered by MSVC code static analyzer .
an exception is ok as long as we have no general catch at the top level :) if we get to to this point an assert would do as well. Just some hint why the system has failed would be useful.