Added https support and better exception handling