Improving region handling code