Make string:trim() easier to read
Split out code to strip extraneous spaces into a function
Replace magic numbers with meaningful names
Generate agegroups and detailed_agegroups lists on the fly instead of hardcoding them in the script