Fixed errors in download logic.