functions for handling bounding boxes around non-zero elements