add locks to resolve -race warnings.