Fix scoping issues with config variable and function scope