def normalize (bbox):
   """
   Normalizes EPSG:4326 bbox order. Returns normalized bbox, and whether it was flipped on horizontal axis.
   """

   flip_h = False
   bbox = list(bbox)
   while bbox[0] < -180.:
        bbox[0] += 360.
        bbox[2] += 360.
   if bbox[0] > bbox[2]:
      bbox = (bbox[0],bbox[1],bbox[2]+360,bbox[3])
      #bbox = (bbox[2],bbox[1],bbox[0],bbox[3])
   if bbox[1] > bbox[3]:
      flip_h = True
      bbox = (bbox[0],bbox[3],bbox[2],bbox[1])
   
   

   return bbox, flip_h