improved bounding box checking