Fix history saving while system shutdown