I really dislike global environment here. Where CFGDIR is defined, why script should rely on it? Can you pass it as an input variable?