fix the multithread bug -- fix the unsafe code