Made the HTTP download code more general and safer.