Bug fix in image generation code