move bounding box check to a seperate function