added https support and did some code cleanup