fix mistake when terminating