refactored extracting rectangle encompassing the ir