Fix region detection functions