fix bug at shutdown