Fix thread problem. Improve stability.