Refactored the function get_image.