almost done with region calculating function