some thread safe code.