Added proper handling of errors during downloads