refactor region code