add thread safe logic