Refactored TemplateRegionParser and PartitionHelpers for better readability.