secure against some possible exceptions while downloading

Change-Id: I61599e6105e2f3e2488413d488f27f3e0a7a5b22