Undo / Redo and State Saving in Javascript