improved logging of errors