Refine download code