Added canUndo and canRedo methods before performing undo and redo