Added some error handling for non-200 HTTP and ill-formed URL
Reorganized some the download function
add some error handling for connection
improve code style; long lines
make display of download progress update in place