fix thread issues and others