Added some threadsafety