move download code to factory