Various c++ fixes by beta-tester