mplemented undo and redo functionality