improve thread safe