better bounding box calculation