Updated script to output error code on failure