Added logging of errors.