Made it threadsafe