Fixed bug in locating ROIs outside the allowed range.