download image + refactored code