undoLast function in place