Fix thread safe issues

Added a local_config when using #with. It should copy the current
global config to current thread, apply the wanted modifications and
work as expected inside the block. Calls to #config and #config= will
return the local_config if it exists.