Merge "Move some logic of removeTask() into TaskRecord."