public String undoTask() {
		int indexOfCommandToUndo = Data.commandList.size() - 1;
		if(indexOfCommandToUndo < 0) {
			return "No previous step detected!";
		} else {
			Command commandToUndo = Data.commandList.get(indexOfCommandToUndo);
			String commandType = commandToUndo.getCommand();
			if(commandType.equals("add")) {
				Data.removeTask(commandToUndo.getTask());
				Data.commandList.remove(indexOfCommandToUndo);
				return "Undo successful!";
			}
			else if(commandType.equals("delete")) {
				Data.task.add(commandToUndo.getIndexOfTaskModified(), commandToUndo.getTask());
				Data.commandList.remove(indexOfCommandToUndo);
				return "Undo successful!";
			}
			else if(commandType.equals("change")) {
				Task oldTask = new Task(true);
				oldTask.setTaskName(commandToUndo.getNameOfTaskModified());
				oldTask.setDueDate(commandToUndo.getDueDate());
				oldTask.setStartDate(commandToUndo.getStartDate());
				oldTask.setStatus(commandToUndo.getStatusOfTask());
				oldTask.setTaskType(commandToUndo.getTypeOfTaskModified());
				Data.task.remove(commandToUndo.getIndexOfTaskModified());
				Data.task.add(commandToUndo.getIndexOfTaskModified(), oldTask);
				Data.commandList.remove(indexOfCommandToUndo);
				return "Undo successful!";
			}
			else if(commandType.equals("complete")) {
				if (!commandToUndo.getStatusOfTask()) {
					Data.task.get(commandToUndo.getIndexOfTaskModified()).setStatus(false);
				}
				Data.commandList.remove(indexOfCommandToUndo);
				return "Undo successful!";
			}
			else if(commandType.equals("clear")) {
				Data.task = commandToUndo.getOldTaskList();
				Data.commandList.remove(indexOfCommandToUndo);
				return "Undo successful!";
			}			
			else {
				Data.commandList.remove(indexOfCommandToUndo);
				return "Last action cannot be undone.";
			}
		}
	}