fix bug in download and remove useless code
fix encoding bug in file generation