Fixing task destruction bug