Added HTTPS support, plus some minor cleanup