Tidy up download function
try to make encoding /decoding clearer
Tidied unicode handling