Refactor submit script to stop submitting when any error occurred