Attempt to make it threadsafe