Refactor create_cfg