Refactor out the bounding box calculation