add thread safe code for service