Make it to work nice in multi-thread

make it to thread safe