added proper state check for failedJob flag.