implemented optimal bounding box orientation