refactored the code a bit to use new https request library