Final working version of code.
Final working code with region source.