Thread safety

agreed, it should be outside the lock