added for-loop in setup_config, minor optimizations and cleanups