made it threadsafe