Fix bug with undo