Scripts: fix some issues found by static code analysis (also fix 2 startup errors)