added counting down to terminate the process when errors occured