changed region calculation code