added save history logic