Fix saving on database close