improved debug logging, better handling of rsponse headers