Fixed various bugs with downloading a file.