Try and fix EOFError in download.py (also a couple of other changes, sorry for the messy commit)