Made some things thread safe.