Fix handling of failed tasks