not sure how many times this will be called, but maybe it's worth defining a local var for performance.
same goes for all cfg properties in the loop - no point in accessing "cfg" for each loop iteration, better to define local vars.