refactored to use HttpURLConnection