Fixed bugs in regions calculation.