I think this code is not threadsafe.