fixes to adal popup write_response (errors) and retry logic