added timeout handling and clean up for UrlConnection