Fix of optimize_images function