extract $config into function as it's used in multiple places