Added history saving and loading