Corrected handling of the image variable for better speed