Remove dependence on a static 'config' variable, which probably explains some of the occasional weird issues that looked like thread-safety problems. Could be optimized more by sharing the setup.