factored out config writing to separate subs