Code updated through flattening the images