Add additional checks for undo and redo here.

Change-Id: I9fde607ce87d4c499bc6adedddc71e726fb8a01c