refactoring and fixing issue with response being overwritten when multiple tasks fail