Better error handling. Moved downloading to its own method.