Refactor some common code for bounding boxes.