rewrite loop to only loop once independent of region sizes