Javascript undo manager