Some refinement to extract_image