fixing bugs with undo