Added a workaround for termination error that occurs sometimes when code does not terminate cleanly.