cleaned up file downloading code