Changed wget to curl and improved error detection.