Updated scripts to exit with error code correctly