Backported improvements from the https branch