fix thread bugs