Fix critical bug in task deletion