Improved async threading code for WebUI