Added file download and better error handling