Change document download method to use curl, refactor