Adding better error handling for tasks