fix exception for non-zero exit code in script
move 'added' var decl closer to usage