Changed to use thread_local.