moved the region handling code into the external module