Make all this new code thread safe