Add msg to bounding box derivation.

This function is pretty much a re-implementation of the python function.
It may need further refactor to separate the logic and settings.