Added finetuning of logging and sending back better results in case of an error.