fixed bounding box function