Improve download image algorithm.